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

Offload source strings from JS heap by using external v8 strings #9675

Closed
AaronO opened this issue Mar 3, 2021 · 1 comment
Closed

Offload source strings from JS heap by using external v8 strings #9675

AaronO opened this issue Mar 3, 2021 · 1 comment
Labels
deno_core Changes in "deno_core" crate are needed suggestion suggestions for new features (yet to be agreed)

Comments

@AaronO
Copy link
Contributor

AaronO commented Mar 3, 2021

This is a specific optimization related to #9660

The problem

Source strings (of runtime JS) take up a decent portion of our baseline-heap, they account for ~1MB of the total ~2.2MB as of 1.8.0, so nearly 50% and is duplicated for each isolate/worker.

The solution

All runtime JS is bundled in the deno binary and available as &'static str so they are inherently immutable, live "forever" and are thus perfect candidates for external strings.

We could simply implement JsRuntime::execute_static, a version of JsRuntime::execute that accepts static filenames and sources and exposes them as external strings to v8.

External strings could possibly be used more broadly, but I think it's best to start with the internal runtime JS.

The impact

We should be able to reduce baseline heap-size by ~1MB or ~50% with little to no downsides (unlike minifying).

The hurdles

This requires extending our rusty_v8 bindings, which is relatively simple (we need to bind to v8::String::NewExternal, expose it twice for one and two-byte strings)

We would also need to ensure that our runtime source files are all truly ASCII (not utf8) if we want to use single-byte strings.

Check if this is compatible with snapshots or what would be required to correct that (from inspecting the heap retainers, all source strings are retained by script_or_debug_info of sub-functions, snapshots without the external strings might result in dangling references that would need to be restored) .

@kitsonk kitsonk added deno_core Changes in "deno_core" crate are needed suggestion suggestions for new features (yet to be agreed) labels Mar 9, 2021
@AaronO AaronO mentioned this issue Mar 18, 2021
24 tasks
@bartlomieju
Copy link
Member

We have already done it, so I'm gonna close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deno_core Changes in "deno_core" crate are needed suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

3 participants