Concerns about weak refs and weak maps.

Allen Wirfs-Brock Allen.Wirfs-Brock at microsoft.com
Fri Oct 29 08:58:37 PDT 2010


Rick and Erik,

I share your concerns about the importance of efficient GC for JavaScript.  However, based upon direct experience, I'm not particularly concerned about the impact of Weak maps.  The ES Harmony Weak Maps is derived from the Ephemeron concept first developed at Digitalk.  We first implemented them in the production GC for Visual Smalltalk and later in ParcPlace-Digitalk (now Cincom) VisualWorks Smalltalk.  These were both high performance, low latency, accurate, moving,  multi-generational collectors that have now been in production use for over 15 years.  In general, Smalltalk application seem to be are much more demanding upon a GC then most modern JavaScript applications (and correspondingly, my perceptions is that JavaSript GCs have not yet reached the sophistication and throughput levels that were typical of Smalltalk GCs).

While the above Smalltalk GCs are multi-generational, neither utilized any parallelism.  They clearly demonstrate that parallelism is not necessary to achieve low pause times in highly interactive GC'ed systems. Regardless, modern collectors exploiting parallelism exist for both Java and .Net that support various weak pointer abstractions.  I'm comfortable that they provide a sufficient existence proof for efficient parallel collectors supporting weak reference semantics.

It is unfortunate, that the use of WeakMaps/Weak pointers/Ephemerons do impose some overhead that is proportional to their  use. But the use of weak abstractions generally shows up in non-ephemeral use cases so this really isn't a problem. Still, they are a feature that shouldn't be used unnecessarily. However, when they are necessary, there really isn't any other good alternative.

I agree that current JavaScript GCs have a lot of issues that  derive from interactions with C/C++ based DOMs.  I think the long term solution is to allocate those objects in the JavaScript GC'ed heap.  My slogan from a recent talk (http://bit.ly/ahiGS1 ): "Build a great GC and then use it everywhere".

Allen




More information about the es-discuss mailing list