Hacker News new | ask | show | jobs
by PavlovsCat 4722 days ago
“in a memory constrained environment garbage collection performance degrades exponentially.” The obvious solution, then, is to throw memory at the problem, no?

Isn't the obvious solution to avoid garbage collection whenever possible? Just consider 'Date.now()' vs 'new Date().getTime()' - are we even trying? Shouldn't we start considering unnecessary garbage a bug, like a memory leak? That might not change everything, but it surely would help, no?

1 comments

That's an interesting idea, but how does a language distinguish between memory leaks and regular non-leaks? Maybe some kind of metadata that informs the GC about how memory will be used so it can optimize memory usage and issue errors when the code fails to follow these rules?

If we really start hitting these kinds of walls, I think that Javascript subsets (like asm.js) will become more prominent, but it's an interesting idea.

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.