Skip to content

fix(protocol/sandbox): restore Wasmtime module LRU cache#5525

Merged
ark0f merged 20 commits into
masterfrom
al/protocol/wasmtime-lru-cache
Jun 1, 2026
Merged

fix(protocol/sandbox): restore Wasmtime module LRU cache#5525
ark0f merged 20 commits into
masterfrom
al/protocol/wasmtime-lru-cache

Conversation

@ark0f
Copy link
Copy Markdown
Member

@ark0f ark0f commented May 27, 2026

Closes #

Summary

Restore the in-memory module cache that was lost during #4860. The old gear-wasmer-cache behavior avoided repeated compilation for already-seen wasm modules; this PR adds the equivalent shared cache for Wasmtime module creation paths.

The change wires the cache into sandbox host, embedded executor, ethexe processor, lazy-pages fuzzer, and calc-stack-height, and adds a Criterion benchmark comparing Wasmtime disk cache lookup with the in-memory LRU path.

How to test

  • CARGO_BUILD_RUSTC_WRAPPER= rtk cargo test -p gear-wasmtime-cache
  • CARGO_BUILD_RUSTC_WRAPPER= rtk cargo clippy -p gear-wasmtime-cache --all-targets
  • CARGO_BUILD_RUSTC_WRAPPER= rtk cargo bench -p gear-wasmtime-cache --bench lru_cache
  • CARGO_BUILD_RUSTC_WRAPPER= rtk proxy cargo clippy -p gear-sandbox-host -p gear-sandbox -p ethexe-processor -p lazy-pages-fuzzer -p calc-stack-height --all-targets

Notes

No breaking changes. The benchmark uses sdk/examples/big-wasm/big.wasm as the repeated module input.

Checklist

  • PR title follows Conventional Commits (type(scope): description)
  • Single logical change
  • Tests added or updated (if logic changed)
  • Docs updated (if needed)

@ark0f ark0f changed the title fix(gear): restore Wasmtime module LRU cache fix(protocol/sandbox): restore Wasmtime module LRU cache May 27, 2026
@ark0f ark0f added type: fix Bug fix correcting incorrect behavior scope: gear Gear protocol labels May 27, 2026
@ark0f ark0f force-pushed the al/protocol/wasmtime-lru-cache branch from fca11ab to 1ea3dd2 Compare May 27, 2026 18:11
@ark0f ark0f marked this pull request as ready for review May 27, 2026 18:15
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request restores an in-memory module cache mechanism previously lost during the migration from Wasmer to Wasmtime. By caching compiled Wasmtime modules, the system avoids repeated compilation for previously encountered Wasm modules, improving performance across various components of the Gear node. The changes include the creation of a dedicated caching crate and its integration into the relevant execution paths, alongside benchmarking to validate the performance impact.

Highlights

  • Wasmtime Module Cache: Introduced a new gear-wasmtime-cache crate providing an in-memory LRU cache for Wasmtime modules to avoid redundant compilation.
  • Integration: Integrated the new cache into the sandbox host, embedded executor, ethexe processor, lazy-pages fuzzer, and calc-stack-height tool.
  • Benchmarking: Added a Criterion benchmark to compare the performance of the new in-memory LRU cache against Wasmtime's disk cache.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ea3dd2664

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread protocol/wasmtime-cache/src/lib.rs Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new crate, gear-wasmtime-cache, which implements an in-memory LRU cache for compiled Wasmtime modules. This cache is integrated across various executors, sandboxes, and tools to reduce compilation overhead. Feedback on the implementation highlights a severe concurrency bottleneck in get_impl where the global mutex lock is held during the slow compilation step (Module::new). It is recommended to release the lock before compiling and re-acquire it when inserting the compiled module into the cache.

Comment thread protocol/wasmtime-cache/src/lib.rs Outdated
@ark0f ark0f added the pr: do-not-merge Must not be merged label May 28, 2026
@ark0f
Copy link
Copy Markdown
Member Author

ark0f commented May 30, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17f389fc47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread protocol/wasmtime-cache/src/lib.rs Outdated
Comment thread protocol/wasmtime-cache/src/lib.rs Outdated
Comment thread protocol/wasmtime-cache/benches/lru_cache.rs Outdated
@ark0f ark0f removed the pr: do-not-merge Must not be merged label May 30, 2026
@breathx breathx added this pull request to the merge queue Jun 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 1, 2026
@ark0f ark0f added this pull request to the merge queue Jun 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 1, 2026
@ark0f ark0f added this pull request to the merge queue Jun 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 1, 2026
@ark0f ark0f added this pull request to the merge queue Jun 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 1, 2026
@ark0f ark0f added this pull request to the merge queue Jun 1, 2026
Merged via the queue into master with commit 903c6c4 Jun 1, 2026
33 checks passed
@ark0f ark0f deleted the al/protocol/wasmtime-lru-cache branch June 1, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: gear Gear protocol type: fix Bug fix correcting incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants