Offload source strings from JS heap by using external v8 strings #9675
Labels
deno_core
Changes in "deno_core" crate are needed
suggestion
suggestions for new features (yet to be agreed)
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 of1.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 ofJsRuntime::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 tov8::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) .The text was updated successfully, but these errors were encountered: