Use cases for WeakMap

Hudson, Rick rick.hudson at intel.com
Tue May 17 07:06:40 PDT 2011


>>This is all a bit off topic but performance does matter and folks seem to be underestimating the wealth of community knowledge that exists in this area.

>Who underestimates?

Sorry, this wasn't meant to slight anyone.  I have spent a career standing on the shoulders of Allen and his colleagues. My respect should not be underestimated.

Interesting pointer.


-        Rick

From: Brendan Eich [mailto:brendan at mozilla.com]
Sent: Monday, May 16, 2011 6:44 PM
To: Hudson, Rick
Cc: Allen Wirfs-Brock; Oliver Hunt; Andreas Gal; es-discuss
Subject: Re: Use cases for WeakMap

On May 16, 2011, at 2:46 PM, Hudson, Rick wrote:


This is all a bit off topic but performance does matter and folks seem to be underestimating the wealth of community knowledge that exists in this area.

Who underestimates?

A bunch of us are aware of all this. Allen certainly knows all about it, and we've been talking shop with him for years, long before he joined Mozilla :-P. I recall a conversation like this one about sparse hashcode implementation with Allen, Lars Thomas Hansen (then of Opera), and Graydon Hoare from four or five years ago...

http://wiki.ecmascript.org/doku.php?id=proposals:hashcodes (check the history)

However, in this thread, the issue is not optimizing hashcode or other metadata sparsely associated with objects. That's a good thing, implementations should do it. Having the hashcode in the object wins, compared to having it (initially) in a side table, but who's counting?

The issue under dispute was neither sparse hashcode nor sparse "fish" property association, where the property would be accessed by JS "user code" that referenced the containing object itself. Rather, it was whether a frozen object needed any hidden mutable state to be a key in a WeakMap. And since this state would be manipulated by the GC, it matters if it's in the object, since the GC would be touching more potentially randomly distributed memory, thrashing more cache.

So far as I can tell, there's no demonstrated need for this hidden-mutable key-in-weakmap object state. And it does seem that touching key objects unnecessarily will hurt weakmap-aware GC performance. But I may be underestimating... :-/

/be

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110517/4145c633/attachment-0001.html>


More information about the es-discuss mailing list