You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we use external strings for internalized builtin source code.
However when a snapshot is taken, any external string whose resource is
not registered is flattened into a SeqString (see ref). The result is
that any module source code stored in the snapshot does not use external
strings after deserialization. This patch registers an external string
resource for each internalized builtin's source. The savings are
substantial: ~1.9 MB of heap memory per isolate, or ~44% of an otherwise
empty isolate's heap usage:
```bash
$ node --expose-gc -p 'gc(),process.memoryUsage().heapUsed'
4190968
$ ./node --expose-gc -p 'gc(),process.memoryUsage().heapUsed'
2327536
```
The savings can be even higher for user snapshots which may include more
internal modules.
Doing this with the existing UnionBytes abstraction was tricky, because
UnionBytes only creates an external string resource when ToStringChecked
is called. However we need to collate a list of external resources
before isolate construction. UnionBytes can also be deallocated, which
isn't ideal since registering an external string resource which is later
deallocated would be very bad.
Rather than further complicate UnionBytes, we introduce a new class
called EternalBytes which assumes that the data has static lifetime and
creates a single external string resource on construction. It reuses
this original external string resource across V8 isolates by simply
ignoring Dispose calls from V8.
In order to distinguish between EternalBytes and UnionBytes, we
bifurcate the sources map into two maps: the internalized builtins map
(which is never modified) and the sources map (which can be changed
through externalized builtins or by the embedder).
Refs: https://github.com/v8/v8/blob/d2c8fbe9ccd1a6ce5591bb7dd319c3c00d6bf489/src/snapshot/serializer.cc#L633
0 commit comments