Skip to content

Use once_cell to cache stdlib compilation in wasm#124

Merged
swernli merged 1 commit intomainfrom
swernli/wasm-std-cache
Apr 3, 2023
Merged

Use once_cell to cache stdlib compilation in wasm#124
swernli merged 1 commit intomainfrom
swernli/wasm-std-cache

Conversation

@swernli
Copy link
Collaborator

@swernli swernli commented Apr 3, 2023

This adds simple caching of the stdlib compilation during check calls using OnceCell. Since the stdlib is static in the wasm layer and the store does not need to be mutable (the compilation unit for the checked user's code is not added to it), this can be done once for the lifetime of the loaded package and reused over and over. In local testing, this produced a 95% perf improvement on the check calls performed as the user types (from 2.3 ms to 0.1 ms).

@swernli swernli requested review from bamarsha and idavis as code owners April 3, 2023 16:30
@swernli
Copy link
Collaborator Author

swernli commented Apr 3, 2023

Of note for those keeping track of what dependencies we are pulling in: the once_cell crate has been under review for inclusion in the Rust stdlib, and was partially stabilized as of rust-lang/rust#105587 so is expected to be in the language as of Rust 1.70. This change intentionally uses only the portion of the API that was stabilized such that the dependency can be dropped and the stdlib implementation used instead once that version of Rust releases.

@swernli swernli requested a review from billti April 3, 2023 16:34
@swernli swernli merged commit cb6e594 into main Apr 3, 2023
@swernli swernli deleted the swernli/wasm-std-cache branch April 3, 2023 18:09
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.

2 participants