denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.01k stars 5.39k forks source link

`deno compile --include-code-cache` #26979

Open felipecrs opened 21 hours ago

felipecrs commented 21 hours ago

Surfing on the new deno compile --include-style flags, it would be great if the compiled binary could have its own code cache included.

Code cache right now will only cache in the first execution and then reuse it in subsequent ones.

As I had stated here, this new flag would make a lot of sense in ephemeral environments like docker containers, where the first execution is also the only execution, rendering code cache a bit useless in this scenario (to be fair, it should be able to work around the issue by running the application once during docker build, but running an application isn't always ok to do).

On my tests on some application, the code cache seems very small:

# let's make sure we don't have any prior cache
❯ deno clean
Removed /home/felipecrs/.cache/deno (7569 files, 86.04MB)

❯ ./pkgx-cc --sync

❯ deno clean
Removed /home/felipecrs/.cache/deno (4 files, **76.27KB)**

Only 76.27 KB in this example. A negligible size increase considering the whole binary size.

Maybe it should be even made the default?

felipecrs commented 21 hours ago

Correction: this is the actual code cache:

❯ ls -lha /tmp/deno-compile-*
-rw-r--r-- 1 felipecrs felipecrs 1.8M Nov 21 14:12 /tmp/deno-compile-pkgx-cc.cache

And the size is not just some KBs, but instead a few MBs. I think it's still very acceptable to be bundled by some applications, but I guess it's a good reason not to do it by default.