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

perf(compile): code cache #26528

Merged
merged 25 commits into from
Nov 18, 2024
Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Oct 24, 2024

Adds a lazily created code cache to deno compile by default.

The code cache is created on first run to a single file in the temp directory and is only written once. After it's been written, the code cache becomes read only on subsequent runs. Only the modules loaded during startup are cached (dynamic imports are not code cached).

The code cache can be disabled by compiling with --no-code-cache.

> hyperfine --warmup 2 scratch.exe scratch_new.exe
Benchmark 1: scratch.exe
  Time (mean ± σ):     282.9 ms ±   6.5 ms    [User: 78.1 ms, System: 15.6 ms]
  Range (min … max):   276.5 ms … 295.2 ms    10 runs

Benchmark 2: scratch_new.exe
  Time (mean ± σ):     129.7 ms ±   6.8 ms    [User: 17.1 ms, System: 9.7 ms]
  Range (min … max):   120.9 ms … 138.4 ms    21 runs

Summary
  scratch_new.exe ran
    2.18 ± 0.13 times faster than scratch.exe

Closes #26502

@dsherret dsherret added this to the 2.1.0 milestone Oct 24, 2024
@felipecrs
Copy link

This is very promising. Have you thought of including the initial code cache inside the compiled executable as well?

@dsherret
Copy link
Member Author

dsherret commented Nov 4, 2024

Yeah, maybe at a later time and as a separate option. The problem is it will make the binary much larger.

@felipecrs
Copy link

felipecrs commented Nov 4, 2024

It all depends on the use case. For some use cases, improving the startup time on the second attempt onwards as opposed to in the first attempt in favor of a reduced binary size will make a lot of sense.

For other cases, it will not make any sense at all. For example: containers. There's only one startup attempt in that case.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -337,6 +380,23 @@ impl ModuleLoader for EmbeddedModuleLoader {
))),
}
}

fn code_cache_ready(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, we should make this method be able to return sync or async response to save some ticks maybe.

@dsherret dsherret enabled auto-merge (squash) November 18, 2024 20:03
@dsherret dsherret merged commit dd4570e into denoland:main Nov 18, 2024
17 checks passed
@dsherret dsherret deleted the perf_compile_code_cache branch November 18, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use code cache in deno compile
3 participants