Skip to content

Make import faster#105

Merged
RogerPodacter merged 1 commit into
evm-backend-demofrom
make_import_faster
Sep 18, 2025
Merged

Make import faster#105
RogerPodacter merged 1 commit into
evm-backend-demofrom
make_import_faster

Conversation

@RogerPodacter

Copy link
Copy Markdown
Member

No description provided.

@RogerPodacter RogerPodacter merged commit f560d0b into evm-backend-demo Sep 18, 2025
1 check passed
@RogerPodacter RogerPodacter deleted the make_import_faster branch September 18, 2025 18:52

Copilot AI left a comment

Copy link
Copy Markdown

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 improves import performance by implementing L1 RPC prefetching, replacing HTTParty with persistent HTTP connections, and adding comprehensive profiling capabilities.

  • Adds concurrent L1 RPC prefetching with configurable thread pools to fetch blocks ahead of time
  • Replaces HTTParty with Net::HTTP::Persistent for better connection reuse and performance
  • Implements detailed import profiling with timing statistics for bottleneck identification

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/l1_rpc_prefetcher.rb New concurrent prefetcher for L1 blocks, receipts, and API data with thread pool management
lib/import_profiler.rb New singleton profiler for timing import operations with thread-safe statistics collection
lib/eth_rpc_client.rb Replaced HTTParty with Net::HTTP::Persistent for connection reuse
lib/block_validator.rb Added concurrent storage verification and profiling integration
config/derive_ethscriptions_blocks.rb Added graceful signal handling for shutdown
app/services/geth_driver.rb Added profiling instrumentation for engine API calls
app/services/eth_block_importer.rb Integrated prefetcher and profiler, removed old RPC result caching

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread lib/l1_rpc_prefetcher.rb

# Only enqueue a reasonable number at once to avoid overwhelming the promise system
# We'll enqueue more as blocks are consumed
max_to_enqueue = [@threads * 20, 100].min # At most 20x thread count or 100

Copilot AI Sep 18, 2025

Copy link

Choose a reason for hiding this comment

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

The magic numbers 20 and 100 should be defined as constants or made configurable through environment variables to improve maintainability.

Copilot uses AI. Check for mistakes.
Comment thread lib/block_validator.rb
@incomplete_actual = true
binding.irb if ENV['DEBUG'] == '1'
next
raise "No receipts returned for L2 block #{block_hash}"

Copilot AI Sep 18, 2025

Copy link

Choose a reason for hiding this comment

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

This changes error handling behavior from continuing with next block to stopping execution entirely. The raise statement will terminate the loop instead of the previous next behavior, which could break existing error handling expectations.

Copilot uses AI. Check for mistakes.
Comment thread lib/block_validator.rb
@incomplete_actual = true
binding.irb if ENV['DEBUG'] == '1'
next
raise "Failed to get receipts for block #{block_hash}: #{e.message}"

Copilot AI Sep 18, 2025

Copy link

Choose a reason for hiding this comment

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

This changes error handling behavior from continuing with next block to stopping execution entirely. The raise statement will terminate the loop instead of the previous next behavior, which could break existing error handling expectations.

Suggested change
raise "Failed to get receipts for block #{block_hash}: #{e.message}"
next

Copilot uses AI. Check for mistakes.
@prefetcher = L1RpcPrefetcher.new(
ethereum_client: @ethereum_client,
ahead: ENV.fetch('L1_PREFETCH_FORWARD', Rails.env.test? ? 5 : 20).to_i,
threads: ENV.fetch('L1_PREFETCH_THREADS', Rails.env.test? ? 2 : 2).to_i

Copilot AI Sep 18, 2025

Copy link

Choose a reason for hiding this comment

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

Line 40 uses the same value (2) for both test and non-test environments. This should likely be different values, such as a higher thread count for production.

Suggested change
threads: ENV.fetch('L1_PREFETCH_THREADS', Rails.env.test? ? 2 : 2).to_i
threads: ENV.fetch('L1_PREFETCH_THREADS', Rails.env.test? ? 2 : 10).to_i

Copilot uses AI. Check for mistakes.
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.

2 participants