Use cases for WeakMap

Brendan Eich brendan at
Mon May 16 15:44:11 PDT 2011

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... (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... :-/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list