deno icon indicating copy to clipboard operation
deno copied to clipboard

perf(core): don't embed source files from extensions

Open bartlomieju opened this issue 2 years ago • 7 comments

This commit changes how "deno_core::Extension" handles JavaScript source files provided by extension. Before this commit, the sources were always embedded into the binary, even though they are only needed during the build process - during build, the sources are loaded into the runtime and snapshotted. This means that we had two copies of the same source files in the resulting binary, even though the embedded ones were never used. This changes results in ~1Mb smaller binary size, at least on macOS.

JavaScript sources for "webgpu" extension were moved from "ext/webgpu/src/" to "ext/webgpu" so all extensions have consistent file structure.

bartlomieju avatar Feb 05 '23 01:02 bartlomieju

If I'm understanding this change correctly, this will make any program using deno_core without snapshots non-distributable. Regardless of whether we want even small users of deno_core to rely on snapshots, this would be a huge footgun, especially for first-time deno_core users.

andreubotella avatar Feb 05 '23 01:02 andreubotella

If I'm understanding this change correctly, this will make any program using deno_core without snapshots non-distributable. Regardless of whether we want even small users of deno_core to rely on snapshots, this would be a huge footgun, especially for first-time deno_core users.

Good catch! I will rework it to allow for both cases.

bartlomieju avatar Feb 05 '23 01:02 bartlomieju

If I'm understanding this change correctly, this will make any program using deno_core without snapshots non-distributable. Regardless of whether we want even small users of deno_core to rely on snapshots, this would be a huge footgun, especially for first-time deno_core users.

Good catch! I will rework it to allow for both cases.

This still doesn't solve the problem, because even if you can choose to make your extensions distributable, 01_core.js will not be. This probably won't be easy to solve, though.

andreubotella avatar Feb 05 '23 17:02 andreubotella

If I'm understanding this change correctly, this will make any program using deno_core without snapshots non-distributable. Regardless of whether we want even small users of deno_core to rely on snapshots, this would be a huge footgun, especially for first-time deno_core users.

Good catch! I will rework it to allow for both cases.

This still doesn't solve the problem, because even if you can choose to make your extensions distributable, 01_core.js will not be. This probably won't be easy to solve, though.

That's right, was just discussing this with @crowlKats. We'll probably always embed them in the binary, they are quite small after all.

bartlomieju avatar Feb 05 '23 17:02 bartlomieju

Okay this is now fixed - there's include_js_files! macro that actually embeds the source and include_js_files_from_crate! which doesn't embed the source but reads it from the crate contents and is meant to be used during snapshotting.

bartlomieju avatar Feb 05 '23 17:02 bartlomieju

Meh, we found some more problems. Gonna convert to draft for now.

bartlomieju avatar Feb 05 '23 18:02 bartlomieju

We used to do this: #10786

And then Aaron reverted because you all didn't like that you could not portably run without snapshotting anymore: #14614

That's the thing that is blocking this PR ATM, need to come up with mechanism that will work in all different situations (creating a snapshot, creating a snapshot from existing snapshot, running without a snapshot, running with a snapshot).

bartlomieju avatar Feb 08 '23 11:02 bartlomieju

Ref https://github.com/denoland/deno/issues/17765

bartlomieju avatar Feb 13 '23 18:02 bartlomieju

Closing in favor of https://github.com/denoland/deno/pull/17826

bartlomieju avatar Feb 20 '23 03:02 bartlomieju