Skip to content

Conversation

@pinebit
Copy link
Collaborator

@pinebit pinebit commented Oct 21, 2025

Summary

Optimize codebase with Go 1.25 features and fix resource leaks across p2p, core, and app packages.

Key improvements:

  • Fixed 6+ timer leaks by replacing time.After with time.NewTimer/NewTicker and proper cleanup
  • Eliminated 3 busy-wait patterns (CPU spinning loops) with efficient channel-based notifications
  • Reduced memory allocations using clear() builtin for map reuse in hot paths
  • Simplified initialization with sync.OnceFunc replacing sync.Once
  • Used builtin min()/max() functions for cleaner code
  • Improved goroutine scheduling with buffered channels
  • Migrated eth1 client to lifecycle management for proper startup/shutdown

Packages affected:

  • p2p/: Timer leaks in bootnode ENR resolution and relay router
  • core/scheduler: Replaced busy-wait loop with channel notifications for epoch resolution
  • core/aggsigdb: Eliminated runtime.Gosched() busy-wait with buffered channel
  • core/parsigex: Fixed timer leak in signature exchange await logic
  • app/retry: Proper timer cleanup on context cancellation
  • app/eth2wrap: Removed time.Sleep busy-wait, added clear() for map reuse
  • app/forkjoin: Buffered results channel for better concurrency

All changes maintain test compatibility and pass race detection.

category: refactor
ticket: none

@codecov
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

❌ Patch coverage is 37.70492% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.76%. Comparing base (b8cfc81) to head (d26511b).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
core/scheduler/scheduler.go 10.34% 24 Missing and 2 partials ⚠️
p2p/bootnode.go 0.00% 17 Missing ⚠️
app/retry/retry.go 25.00% 8 Missing and 1 partial ⚠️
p2p/p2p.go 38.46% 8 Missing ⚠️
core/parsigex/memory.go 61.53% 5 Missing ⚠️
p2p/relay.go 0.00% 5 Missing ⚠️
app/eth2wrap/httpwrap.go 0.00% 4 Missing ⚠️
app/app.go 0.00% 1 Missing ⚠️
app/eth2wrap/eth2wrap.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4039      +/-   ##
==========================================
- Coverage   53.83%   53.76%   -0.08%     
==========================================
  Files         242      242              
  Lines       39348    39412      +64     
==========================================
+ Hits        21184    21190       +6     
- Misses      15922    15979      +57     
- Partials     2242     2243       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zero O
input = make(chan I, options.inputBuf)
results = make(chan Result[I, O])
results = make(chan Result[I, O], options.workers)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we make this channel buffered? Are we sure it won't break some things down the line, as it changes its behaviour

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As it was explained by Claude, there was extreme goroutines contention here and this buffer resolves it. We have good test coverage for this object, so I am sure it did not break anything. However, it's hard to estimate the effect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed 1:1, reverted this change.

// Copyright © 2022-2025 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1

package aggsigdb

Copy link
Collaborator

Choose a reason for hiding this comment

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

TBH we can revisit this memorydbV2.
Now that we have metrics of the types of feature flags operators have turned on, we can see how many have this V2 DB. I personally do not have the perspective how much it improves Charon.
I can do it as part of looking into the aggregation failures we see recently, as they are related to the DB.

@sonarqubecloud
Copy link

@pinebit pinebit added the merge when ready Indicates bulldozer bot may merge when all checks pass label Oct 21, 2025
@obol-bulldozer obol-bulldozer bot merged commit 938ab64 into main Oct 21, 2025
12 checks passed
@obol-bulldozer obol-bulldozer bot deleted the pinebit/various-optimizations branch October 21, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge when ready Indicates bulldozer bot may merge when all checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants