Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: register external references for source code #47055

Merged
merged 2 commits into from
May 10, 2023

Commits on Apr 9, 2023

  1. src: register external references for source code

    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 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:
    
    ```console
    $ 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.
    
    The existing UnionBytes implementation was ill-suited, because it only
    created an external string resource when ToStringChecked was called,
    but we need to register the external string resources before the
    isolate even exists. We change UnionBytes to no longer own the data,
    and shift ownership of the data to a new external resource class
    called StaticExternalByteResource.  StaticExternalByteResource are
    either statically allocated (for internalized builtin code) or owned
    by the static `externalized_builtin_sources` map, so they will only be
    destructed when static resources are destructed. We change JS2C to emit
    statements to register a string resource for each internalized builtin.
    
    Refs: https://github.com/v8/v8/blob/d2c8fbe9ccd1a6ce5591bb7dd319c3c00d6bf489/src/snapshot/serializer.cc#L633
    kvakil committed Apr 9, 2023
    Configuration menu
    Copy the full SHA
    a0bd46c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cd42560 View commit details
    Browse the repository at this point in the history