- 
                Notifications
    You must be signed in to change notification settings 
- Fork 116
perf(l1): reusing FindNode message per lookup loop #5047
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
          
     Merged
      
      
    
                
     Merged
            
            
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    | Lines of code reportTotal lines added:  Detailed view | 
              
                    MegaRedHand
  
              
              approved these changes
              
                  
                    Oct 24, 2025 
                  
              
              
            
            
              
                    edg-l
  
              
              approved these changes
              
                  
                    Oct 27, 2025 
                  
              
              
            
            
| Benchmark Block Execution Results Comparison Against Main
 | 
    
  iovoid 
      pushed a commit
      that referenced
      this pull request
    
      Oct 27, 2025 
    
    
      
  
    
      
    
  
**Motivation** Noticed that random key creation for FindNode messages was consuming a lot of CPU: <img width="1860" height="563" alt="image" src="https://github.com/user-attachments/assets/9d823161-6013-41fe-94b1-008803edb353" /> **Description** So, instead of creating a new key on each message, we create a FindNode message on every lookup cycle, and encode it a single time to send to all peers. It removes some randomness but gains in performance. In any case, next lookup cycle will create a new key. New flamegraph: <img width="1854" height="539" alt="image" src="https://github.com/user-attachments/assets/d2b42609-e178-4ec7-a1a7-31230926c06e" /> Tested on mainnet to see if it reduced peer finding performance, and it took 3' 24'' to find 50 peers ``` 2025-10-24T18:48:42.213697Z INFO ethrex_p2p::network: P2P Snap Sync: elapsed: 00h 03m 23s 00ms 50 peers. Current step: Downloading Headers ``` and 13' 43'' to reach the 100 peers limit: ``` 2025-10-24T18:59:02.280007Z INFO ethrex_p2p::network: P2P Snap Sync: elapsed: 00h 13m 43s 00ms 100 peers. Current step: Downloading Headers ``` --------- Co-authored-by: Edgar <[email protected]>
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Motivation

Noticed that random key creation for FindNode messages was consuming a lot of CPU:
Description
So, instead of creating a new key on each message, we create a FindNode message on every lookup cycle, and encode it a single time to send to all peers. It removes some randomness but gains in performance. In any case, next lookup cycle will create a new key.
New flamegraph:

Tested on mainnet to see if it reduced peer finding performance, and it took 3' 24'' to find 50 peers
and 13' 43'' to reach the 100 peers limit: