Mutable array methods
bruant.d at gmail.com
Mon Mar 19 14:36:12 PDT 2012
Le 19/03/2012 21:10, Maël Nison a écrit :
> I'm 'upping' this discussion for two reasons :
> - I didn't send any response before ! I didn't know that some parts of
> V8 were self-hosted, so I'm glad to have learn that. Thanks. : )
> - I've just read this article  on the web, and it reminds me this
> discussion. The author is explaining a valid use case of mutable
> functions (preventing useless garbage collection). It's true that in
> real time application, garbage collection consume a lot of processing
> time (factories or persistent objects are not uncommon   ).
> What do you think about this ?
My opinion hasn't changed. You can still add these methods yourself to
Array.prototype. You are even encouraged to do that and remove methods
abusively creating new arrays if it helps promote array reusability in
your own code.
Regarding garbage collection, I diverged a thread at some point to start
about garbage collection . Allen had really interesting points about
how garbage collection works or could work. Modern web browsers are
"Garbage collection consumes a lot of processing time" because people
use it a lot by creating and not reusing. The problem does not come from
the collector, but from those who generate the garbage. Very much like
for actual garbage ;-)
Garbage collection gives the false impression to programmers that they
can stop worrying about memory. But this is a... false impression. You
the memory you've already allocated, you obviously pay it somewhere else.
It's somewhat depressing that someone has to write a blog post to say
"reuse things that are already allocated".
>  https://github.com/arcanis/spark.js/blob/master/lib/factory.js
>  https://github.com/zz85/sparks.js/blob/master/Sparks.js#L847
>  https://github.com/mrdoob/three.js/blob/master/src/core/Matrix4.js#L1038
More information about the es-discuss