-
Couldn't load subscription status.
- Fork 114
refactor(l1): remove Mutex from profiling metrics
#5031
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the profiling metrics implementation by removing a centralized Mutex that could cause contention as more functions are instrumented. The change leverages per-span RwLock mechanisms already present in the tracing infrastructure.
Key changes:
- Replaced the
HashMap<Id, HistogramTimer>wrapped in aMutexwith per-span storage using span extensions - Introduced a
ProfileTimerwrapper struct to avoid conflicts with other layers - Updated instantiation to use unit struct instead of
default()
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/blockchain/metrics/profiling.rs | Removed centralized Mutex-protected HashMap and implemented per-span timer storage using span extensions |
| cmd/ethrex/initializers.rs | Updated FunctionProfilingLayer instantiation to use unit struct syntax |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Lines of code reportTotal lines added: Detailed view |
**Motivation** Having a centralized `Mutex` in the profiling metrics could potentially make code slower, the more functions we instrument. Removing it reduces the noise we have in our measurements. **Description** This PR replaces the singleton `Mutex` by using the internal `RwLock` that spans already have for layers to store things. Disabling metrics doesn't seem to increase performance in a noticeable manner, so this shouldn't increase performance. --------- Co-authored-by: Edgar <[email protected]>
Motivation
Having a centralized
Mutexin the profiling metrics could potentially make code slower, the more functions we instrument. Removing it reduces the noise we have in our measurements.Description
This PR replaces the singleton
Mutexby using the internalRwLockthat spans already have for layers to store things. Disabling metrics doesn't seem to increase performance in a noticeable manner, so this shouldn't increase performance.