Skip to content

Move re-initialization logic into Rust/wasm-bindgen#947

Draft
logan-gatlin wants to merge 24 commits intomainfrom
logan/remove-reinit-for-unwind
Draft

Move re-initialization logic into Rust/wasm-bindgen#947
logan-gatlin wants to merge 24 commits intomainfrom
logan/remove-reinit-for-unwind

Conversation

@logan-gatlin
Copy link
Copy Markdown
Collaborator

@logan-gatlin logan-gatlin commented Mar 10, 2026

This PR moves (most of) the responsibility for re-initializing Rust workers away from our custom JS shim, and into Rust/wasm-bindgen.

Latest wasm-bindgen handles re-initialization automatically when building for the panic=unwind target. This means that most of the shim we provide for WASM modules is unnecessary. This PR creates a new minimal shim for panic=unwind builds.

Durable objects require slightly more work since their state must be reset on an abort. Previously, durable objects were heap allocated Rust structs managed by JS objects which kept pointers into Rust's memory. This is problematic when the instance resets, as these pointers become dangling.

The new design is to keep a global HashMap in Rust containing all live DO instances, keyed by a unique u32. In our JS shim, we maintain a list of live DO ids and the arguments used to construct them. When re-initialization happens, every entry in this list is re-initialized.

Notes:
This requires a new feature in wasm-bindgen allowing for a post-reinitialization hook, right now I am just pointing the submodule to my feature branch. Both Rust and wasm-bindgen needed to be bumped to their latest version so I could write panic=unwind tests. This makes the diff messy because many doc tests subsequently failed to build, and CI had to be modified to support this new setup. When the wasm-bindgen reinit hook is merged I will probably split this up into two PRs

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 10, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 2 untouched benchmarks


Comparing logan/remove-reinit-for-unwind (ac104bc) with main (2d022ab)

Open in CodSpeed

Comment thread worker-build/src/main.rs Outdated
Copy link
Copy Markdown
Collaborator

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

Would be nice to see how this integrates with the upstream branch of supporting StaleError and if that is sufficient to support the instance checks.

We also need to ensure unwind test coverage here.

Comment thread worker-build/src/main.rs Outdated
@logan-gatlin logan-gatlin force-pushed the logan/remove-reinit-for-unwind branch from cef1a38 to 62f9763 Compare March 11, 2026 21:09
@logan-gatlin logan-gatlin force-pushed the logan/remove-reinit-for-unwind branch from 7ad45cd to 11ef7cc Compare March 11, 2026 23:18
@logan-gatlin
Copy link
Copy Markdown
Collaborator Author

logan-gatlin commented Mar 12, 2026

This PR broke doctests somehow, probably because I bumped the versions of a lot of things. Had to go in and add ignore and norun in places

@logan-gatlin logan-gatlin changed the title Remove re-init shim for panic=unwind builds Move re-initialization logic into Rust/wasm-bindgen Mar 18, 2026
@logan-gatlin
Copy link
Copy Markdown
Collaborator Author

I updated this to use the new fork of reinit-hooks wasm-bindgen/wasm-bindgen#5059

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.

3 participants