5 ms·
This looks so advanced, Firefox is the best! I'm very curious to watch how WeakMap behaves and how it is visualized in this tool! Speaking of WeakMap, perhaps
by EdSharkey 11y ago
This looks so advanced, Firefox is the best!
I'm very curious to watch how WeakMap behaves and how it is visualized in this tool!
Speaking of WeakMap, perhaps a Firefox engineer could satisfy my curiosity on this subject. What is the algorithm Firefox uses to release weakly held references? Or, perhaps better restated: how aggressive is Firefox in holding on to weakly referenced objects?
When the majority of new JS memory allocations on a page get placed into WeakMaps, does Firefox always continue to allocate memory from the host OS, or is there some threshold where it starts to let things slip? Also, is there any rhyme or reason to what gets released first from WeakMaps?
Can Firefox run wild like it does with strongly held references, allocating into WeakMaps until the host OS cannot satisfy new native memory allocation requests and only then start to release weak references?
Also, how crazy do things get for you when you put lots of DOM objects or, even worse, GPU-backed memory structures like CanvasPattern into a WeakMap? Please share cool war stories! ;)
Disclaimer: I have not used WeakMap in any serious capacity, so I don't know what I'm talking about.
- mnemonik 11y agoUp until a couple months ago, it had an O(n^2) marking algorithm that kept iterating until it got to a fixed point. Thanks to the hard work of Steve Fink, these days it has an O(n) marking algorithm. See https://bugzilla.mozilla.org/show_bug.cgi?id=1164294 https://bugzilla.mozilla.org/show_bug.cgi?id=1164294 for the details. Edit to address your questions more directly: > how aggressive is Firefox in holding on to weakly referenced objects? They are just collected at the next GC slice where they are no longer retained. SpiderMonkey doesn't do anything to try and eagerly collect them. GC slices generally won't happen until either there has been enough pressure (allocations) to trigger one or the user is inactive for N amount of time. There are tons of GC triggering heuristics and some are probably not optimal. It is on the GC team's TODO list to revisit and clean these up. > does Firefox always continue to allocate memory from the host OS, or is there some threshold where it starts to let things slip? The threshold of how much is allocated before triggering GC grows as the retained set's size grows. This is bounded by available memory. Aaaaand I have a meeting I need to go attend.
- EdSharkey 11y agoI am eating this up! I love you, man. (Not long stares, cuddling love. Like, brotherly.)
- kohlerm 11y agoIt does not seem to support a dominator tree view. That will be missed for serious investigations.