Repository navigation
perf: memory map cached wasm plugins on unix - #1318
Merged
Merged
Conversation
Loads a cached compiled wasm plugin by memory mapping the file instead of reading it, falling back to reading when mapping fails. Windows doesn't allow replacing or deleting a mapped file, so when that fails for a cached plugin, kill the dprint lsp and editor-service processes using the same cache directory and try again.
Windows doesn't allow replacing or deleting a mapped file, and working around that by killing other dprint processes isn't worth it for the smaller gain there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On unix, loads a cached compiled wasm plugin with wasmtime's
Module::deserialize_file, which memory maps the.cwasmand pages it in lazily, instead of reading the whole file and copying it into executable memory. If mapping fails (for example a cache directory on anoexecmount), it falls back to reading the file as before.Windows keeps reading the file. It doesn't allow replacing or deleting a file that another process has mapped, so mapping there would let a running
dprint lsp/editor-service(or any concurrent dprint run) blockclear-cacheand recompiling a plugin. An earlier revision of this PR enabled it on Windows and killed those processes when a delete or replace failed; that was removed because the gain there is smaller (about 7 ms of 22) and not worth the complexity.Measurements
Warm plugin cache, hyperfine means, Ubuntu under WSL2 on a 32-core machine. "5 plugins" is typescript, json, markdown, toml and dockerfile.
checkone filecheckfour small filesoutput-resolved-configcheckthis repo, no incrementalThe first row is from the final revision. The other rows were taken with an earlier revision that had the same load path on Linux. The whole-repo run is within noise, so this is a fixed saving per invocation.
Safety
deserialize_filerequires that the file not change while the module is alive. The cache only replaces a.cwasmby writing a temp file and renaming it over, or deletes it, and on unix both leave an existing mapping of the old file intact. Checked on Linux:Not covered
noexecfallback was not tested on a realnoexecmount.