Is `undefined` garabage collectable?
rossberg at google.com
Mon May 9 09:28:57 UTC 2016
The `undefined` value is represented in exactly the same way as `true`,
`false`, and `null` in V8. They're so called "oddballs" internally, global
values that are neither allocated nor freed.
Either way, the key/values of a (regular) map do not keep anything alive
about the map. Adding or removing entries from a set or map can of course
cause allocation/deallocation, regardless of the keys/values themselves.
(Similarly if you are using regular objects as maps, btw.)
There are also lots of other things that cause allocation/deallocation
deoptimisation, etc. Some of that predominantly happens at start-up. If you
want to reduce random noise from your experiments, try to warm up the code
first. But even then, don't read too much into micro-benchmarks -- JS VMs
are far too complicated, dynamic, and heuristics-based to draw useful
conclusions from tiny tests (that's e.g. why JSPerf tests are often
potentially cause allocation and thus GC. Certainly nothing involving
dynamic data structures.
On 5 May 2016 at 07:48, /#!/JoePea <joe at trusktr.io> wrote:
> > The only v8 shell I have lying around is too old (220.127.116.11) to have
> Set, so I can't tell you what it would do.
> On my first attempt, I noticed 8 Major GCs:
> On second attempt, no Major GCs:
> I wonder why. I'm in Chrome 50.
> So, the second attempt looks good. I'm not sure why the first is so
> different. I tried it a few times, but I only got that Major GC zig-zag the
> first time.
> Thanks for pointing out Set!
> On Wed, May 4, 2016 at 7:30 PM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
>> On 5/4/16 5:03 PM, Steve Fink wrote:
>>> The only v8 shell I have lying around is too old (18.104.22.168) to have
>>> Set, so I can't tell you what it would do.
>> I have v8 "4.8.0 (candidate)" (meaning whatever rev I checked out), and
>> it does 1163 minor ("Scavenge") GCs on your testcase. It also does 1163
>> minor GCs if I take out the add() calls. It does none if I remove the
>> clear() calls, no matter whether the add() calls are there or not.
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss