Skip to content

Conversation

@holiman
Copy link
Contributor

@holiman holiman commented Nov 20, 2024

This came from an alloc dump on a running sync (mingeth).
Screenshot 2024-11-20 at 09-55-10 tinygeth alloc_objects

Quite a lot of bytes are allocated temporarily when we write to db (batches), in order to construct the keys. These allocs are very shortlived, since the write-operations are not allowed to hold on to the keys, but instead copies it to some interrnal buffers.

This PR changes some of the most heavy mass-write-locations to reuse a key buffer. The locations are for example writing accounts received over snapsync, storage received over snapsync and merging in-memory snapshot-changes to disk.

Not sure how large effect this has. I suspect not a whole lot, but I'll run a benchmark sync and see if it anything is discernable.

Not high prio

@rjl493456442
Copy link
Member

Can you measure the reduction in memory allocations achieved by applying this change? Please evaluate its impact during both snap sync and full sync.

This pull request introduces optimizations to reuse the buffer for keying. These changes are only meaningful if they result in a obvious reduction in memory allocations.

@rjl493456442
Copy link
Member

rjl493456442 commented Jan 21, 2025

Instead of reusing the same provided buffer for key construction, we can consider defining a global-shared byte slice pool and use it for all db APIs.

The implementation can be channel based, e.g. https://github.com/ethereum/go-ethereum/pull/30743/files#diff-81c34779bf9837c7e60ee5a804bb5e951fa34ae8a47a6a6dd1e9bfcea868d728

I will have an attempt and benchmark the performance impact later.

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.

4 participants