-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(cli, runtime): compress snapshots #13320
Conversation
1mb saved? Is it worth the complexity? |
@ry 33% improvement in startup time! |
I think this looks really good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question: why lzzzz instead of (lz4_flex)[https://crates.io/crates/lz4_flex]? The latter is the more popular crate and is pure Rust.
runtime/js.rs
Outdated
let mut vec = Vec::with_capacity(size); | ||
|
||
unsafe { | ||
vec.set_len(size); | ||
} | ||
|
||
lzzzz::lz4::decompress(&COMPRESSED_CLI_SNAPSHOT[4..], &mut vec).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably an academic concern but I think writing to uninitialized memory like this is technically undefined behavior. The blessed path is to use MaybeUninit: https://doc.rust-lang.org/std/mem/union.MaybeUninit.html#out-pointers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no undefined behavior in this case, we are just reusing previous allocation without zeroing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue MaybeUninit
is much clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just checked, and Vec::with_capacity
calls the allocator without guaranteeing that the memory has been zeroed. Sure, the allocation might've actually been reused, or it might be a new allocation that actually has been zeroed, but even if we could guarantee that it's either of those cases, I'm pretty sure the language treats the result of an allocation as uninitialized memory, which means that creating values from it, even u8
values, would be undefined behavior.
I initially used lz4_flex for proof of concept but switched to lzzzz because it has lz4hc and is slightly faster at decompressing cli snapshot |
It turns out that the embedder can take selectively compress snapshots, resulting in better startup performance and a smaller binary size. See denoland/deno#13320.
It turns out that the embedder can take selectively compress snapshots, resulting in better startup performance and a smaller binary size. See denoland/deno#13320.
It turns out that the embedder can selectively compress snapshots, resulting in better startup performance and a smaller binary size. See denoland/deno#13320.
It turns out that the embedder can selectively compress snapshots, resulting in better startup performance and a smaller binary size. See denoland/deno#13320.
@piscisaureus I guess we'll wait with landing this PR until we upgrade |
There's no need; snapshots are already off in the current version of rusty_v8. |
Deno does its own snapshot compression using lz4 and zstd, so no need to build zlib into V8. See denoland/deno#13320
Deno does its own snapshot compression using lz4 and zstd, so no need to build zlib into V8. See denoland/deno#13320
Deno does its own snapshot compression using lz4 and zstd, so no need to build zlib into V8. See denoland/deno#13320
depends on denoland/rusty_v8@1cedb0e reversal
replaces v8 zlib compression with lz4 and zstd for better speed and compression ratio
deno run
with cache (cli snapshot)deno-new run -A b.ts
deno-uncompressed run -A b.ts
deno-v8-compressed run -A b.ts
deno cache
with no cache (tsc snapshot)deno-new cache -r b.ts
deno-uncompressed cache -r b.ts
deno-v8-compressed cache -r b.ts
deno run
with no cache (cli + tsc snapshot)deno-new run -r -A b.ts
deno-uncompressed run -r -A b.ts
deno-v8-compressed run -r -A b.ts
test source