Skip to content

Conversation

@Giulio2002
Copy link
Contributor

@Giulio2002 Giulio2002 commented Dec 25, 2025

This PR introduces a warmup cache for the commitment trie processing that reduces redundant DB reads during block execution. Data fetched during the warmup phase is cached and reused during the actual trie computation, improving performance.

Key Changes

  • New WarmupCache - A cache that stores pre-fetched branch, account, and storage data using maphash.Map for efficient byte slice lookups without allocations
  • Cache integration in Warmuper - The warmuper now optionally caches data it reads, making it available during trie processing
  • BranchEncoder cache support - Branch lookups check the cache first before hitting the DB
  • Key eviction - Keys being modified are evicted from the cache to ensure consistency

Architecture Diagram

┌─────────────────────────────────────────────────────────────────────┐
│                        Block Execution                               │
└─────────────────────────────────────────────────────────────────────┘
                                  │
                                  ▼
┌─────────────────────────────────────────────────────────────────────┐
│                          Warmuper                                    │
│  ┌──────────────────┐    ┌──────────────────┐                       │
│  │  Parallel Workers │───▶│   WarmupCache    │                       │
│  │  (prefetch data)  │    │                  │                       │
│  └──────────────────┘    │  ┌────────────┐  │                       │
│                          │  │  branches  │  │                       │
│                          │  ├────────────┤  │                       │
│                          │  │  accounts  │  │                       │
│                          │  ├────────────┤  │                       │
│                          │  │  storage   │  │                       │
│                          │  └────────────┘  │                       │
│                          └────────┬─────────┘                       │
└───────────────────────────────────┼─────────────────────────────────┘
                                    │
                    ┌───────────────┴───────────────┐
                    │         Cache Lookup          │
                    ▼                               ▼
         ┌─────────────────┐             ┌─────────────────┐
         │   Cache Hit     │             │   Cache Miss    │
         │  (return data)  │             │   (read DB)     │
         └─────────────────┘             └─────────────────┘
                                                  │
                                                  ▼
┌─────────────────────────────────────────────────────────────────────┐
│                     HexPatriciaHashed Trie                          │
│                                                                      │
│   Process() ──▶ BranchEncoder.CollectUpdate()                       │
│                        │                                             │
│                        ▼                                             │
│              ┌─────────────────┐                                    │
│              │ Check WarmupCache│                                    │
│              │   for branch     │                                    │
│              └────────┬────────┘                                    │
│                       │                                              │
│           ┌───────────┴───────────┐                                 │
│           ▼                       ▼                                 │
│     Cache Hit               Cache Miss                              │
│   (skip DB read)          (read from DB)                            │
│                                                                      │
└─────────────────────────────────────────────────────────────────────┘
                                  │
                                  ▼
┌─────────────────────────────────────────────────────────────────────┐
│                      Key Eviction Flow                              │
│                                                                      │
│   Updates.HashSort() ──▶ For each modified key:                     │
│                              cache.EvictKey(key)                    │
│                                                                      │
│   (Ensures modified keys are re-read from DB, not stale cache)     │
└─────────────────────────────────────────────────────────────────────┘

Giulio added 2 commits January 3, 2026 22:37
@Giulio2002 Giulio2002 enabled auto-merge (squash) January 5, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants