Hacker News new | ask | show | jobs
by PavlovsCat 4722 days ago
Then know that it was your interesting idea, since I wasn't thinking of anything automatic myself :) Maybe is possible to automate things like generating code that minimizes branching, or re-uses objects instead of destroying and allocating them all the time... but it's definitely possible, in some cases at least, to rethink the approach and reduce GC. Especially since there are usually trade-offs (using a fixed amount of memory "just in case" is distasteful for its own reasons), and the programmer might need to make an informed decision.

But people still need to be aware of it first; making new objects for one time use is handy, and the normal way to go about things. It's certainly the default way tutorials tell you to get the time (even in game loops). At least personally, before today I didn't even know about Date.now(), and I never saw a discussion about any of this stuff in regards to libraries (how good or sloppy they are with GC)... it just doesn't seem to be on the radar, outside of gamedev. And by the time stuff gets sluggish by the accumulated little objects here and there, there is no easy fix, other than a whole lot refactoring or rewriting from scratch with it in mind.