Skip to content

Replace atomic operations with Once in backend/util #4503

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Chain-Fox
Copy link

@Chain-Fox Chain-Fox commented May 5, 2025

Fix #4502

The fix is to use OnceLock Once and atomic variables (for older Rust versions) to replace the original two atomic variables.
OnceLock guarantees the hash can only be initialized once.
This reduces the race condition and provides a slightly better performance.

I also add a test to it to ensure the result before and after patch is consistent.

@Chain-Fox Chain-Fox force-pushed the fix-race-condition2 branch 2 times, most recently from 441c36c to 841f8e1 Compare May 5, 2025 07:39
@Chain-Fox Chain-Fox force-pushed the fix-race-condition2 branch from 841f8e1 to cbac5f7 Compare May 5, 2025 07:53
@Chain-Fox Chain-Fox changed the title Replace atomic operations with OnceLock in backend/util Replace atomic operations with Once in backend/util May 6, 2025
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.

Race Condition and Performance Regression in wasm-bindgen util.rs
1 participant