Skip to content

Conversation

SatoshiIsHere
Copy link
Contributor

This PR implements sync.Pool optimization for []common.Hash slice allocations in PathDB lookup functionality, addressing the TODO comments in triedb/pathdb/lookup.go.

list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool

Implemented a sync.Pool for []common.Hash slices following the established patterns used in other parts of the codebase (e.g., core/types/hashing.go, core/vm/memory.go):

var hashSlicePool = sync.Pool{
    New: func() interface{} {
        return make([]common.Hash, 0, 16)
    },
}

The implementation follows the same sync.Pool patterns used throughout the go-ethereum codebase
Deliberately chose not to implement Put() operations to avoid potential data corruption since the slices are stored in maps and shared across goroutines
The approach prevents race conditions that could occur if slices were returned to the pool while still being referenced in the lookup maps

-go test ./triedb/pathdb/ - 67 tests passed
-go test ./triedb/... - All triedb packages tested
-go test ./core/state/ - StateDB compatibility confirmed

@rjl493456442 rjl493456442 self-assigned this Jul 9, 2025
@rjl493456442
Copy link
Member

The implementation is incorrect, we also need to evaluate the benefits/cost by using the sync pool for bytes slice.

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