Skip to content

Conversation

@MegaRedHand
Copy link
Collaborator

@MegaRedHand MegaRedHand commented Oct 23, 2025

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.

@MegaRedHand MegaRedHand requested a review from a team as a code owner October 23, 2025 21:14
Copilot AI review requested due to automatic review settings October 23, 2025 21:14
@MegaRedHand MegaRedHand added the L1 Ethereum client label Oct 23, 2025
Copy link
Contributor

Copilot AI left a 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 a Mutex with per-span storage using span extensions
  • Introduced a ProfileTimer wrapper 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.

@github-actions
Copy link

Lines of code report

Total lines added: 0
Total lines removed: 3
Total lines changed: 3

Detailed view
+-----------------------------------------------+-------+------+
| File                                          | Lines | Diff |
+-----------------------------------------------+-------+------+
| ethrex/crates/blockchain/metrics/profiling.rs | 55    | -3   |
+-----------------------------------------------+-------+------+

@github-project-automation github-project-automation bot moved this to In Review in ethrex_l1 Oct 27, 2025
@edg-l edg-l enabled auto-merge October 27, 2025 08:39
@edg-l edg-l added this pull request to the merge queue Oct 27, 2025
Merged via the queue into main with commit 5346ed2 Oct 27, 2025
29 checks passed
@edg-l edg-l deleted the remove-mutex-from-profiling-metrics branch October 27, 2025 09:44
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Oct 27, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in ethrex_performance Oct 27, 2025
iovoid pushed a commit that referenced this pull request Oct 27, 2025
**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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client metrics tech debt Refactors, cleanups, etc

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants