Concerns about weak refs and weak maps.

Brendan Eich brendan at mozilla.com
Fri Oct 29 10:08:56 PDT 2010


On Oct 29, 2010, at 3:57 AM, Erik Corry wrote:

> 2010/10/29 Brendan Eich <brendan at mozilla.com>:
>> On Oct 29, 2010, at 12:08 AM, Erik Corry wrote:
>> 
>>> One of the hallmarks of a real language implementation vs. a 'toy
>>> scripting language' ala PHP is a good GC.  I'd really like to see
>>> someone do a low-latency GC with weak maps before we hobble the
>>> language with something that can't be implemented efficiently.

Complex problems don't go away by renouncing any "in language" solution. The complexity moves to the pure-JS level and whatever solution can be hacked there, which then has to be downloaded, and which has bad performance or memory-leak hazards. This then tends to produce non-standard native implementations in various engines. Just noting this, more below.


>> Any chance you guys will implement the WeakMap proposal?
> 
> I can't see Google's V8 team doing that, but anyone can take V8 and do
> experiments on their branch of it.

Cool, maybe we can find a volunteer. Google has projects using JS to manage objects, where I believe in at least one case (Caja), WeakMaps would be a significant win. Such use-cases are not unique to Google, they're common in JS libraries and virtualization schemes. But my first thought is to scour Google for people who need WeakMaps and who could implement an experimental patch for V8.

As people have noted in this thread, you can't really make up for the lack of WeakMaps in JS currently without falling into O(n^2) complexity traps (arrays of objects, linear search). The strong references in such maps make for guaranteed memory leaks. If there's another alternative that lacks both GC complexity and user-facing leak and performance issues, we are all ears. Doing nothing is likely to bid forth extensions in browser JS implementations, which may lead to de-facto standardization.

We can keep experimenting with WeakMaps, but if we don't have an understanding of why demand for something like them exists and is likely to create a standard of some sort, we won't have a fruitful discussion, and we probably won't serve JS users well.

Renouncing WeakMaps certainly would keep GC implementations, e.g., in V8, simpler, but that's too narrow a point of view for Ecma TC39. And if Apple and other vendors do implement some kind of weak map, market pressure may force V8 to follow. This is not the "Harmony" way to proceed, since it tends to make more non-interoperation and developer pain in the market, and take longer.

Nevertheless, it sounds like we should reconsider the move of WeakMaps into "harmony" status (http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps) based on your feedback, moreso than Rick's due to your representing the V8 team. We can move the proposal back to strawman status, pending more results of experiments (plural, so we need help; SpiderMonkey is not enough). Is this your intention?

/be


More information about the es-discuss mailing list