Skip to content
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

Add NewBatchWithSize API for db and use this API for BloomIndexer.Commit() #1240

Merged
merged 2 commits into from
Dec 16, 2022

Conversation

kyrie-yl
Copy link
Contributor

@kyrie-yl kyrie-yl commented Dec 14, 2022

Description

This PR sync from ethereum to preallocate memory in bloom filter when the approximate size of batch is
known in advance.

Rationale

Leveldb also offers another API called MakeBatch which can
pre-allocate the memory area. So if the approximate size of batch is
known in advance, this API can be used in this case.

And it's possible that get the need memory size to Batch for BloomIndexer.Commit() in advance.
So it seems better to use NewBatchWithSize() than NewBatch().

Example

None

Changes

  • adds an addtional API called NewBatchWithSize for db
    batcher
  • use NewBatchWithSize() than NewBatch() for BloomIndexer.Commit()

…(#24392)

This PR adds an addtional API called `NewBatchWithSize` for db
batcher. It turns out that leveldb batch memory allocation is
super inefficient. The main reason is the allocation step of
leveldb Batch is too small when the batch size is large. It can
take a few second to build a leveldb batch with 100MB size.

Luckily, leveldb also offers another API called MakeBatch which can
pre-allocate the memory area. So if the approximate size of batch is
known in advance, this API can be used in this case.

It's needed in new state scheme PR which needs to commit a batch of
trie nodes in a single batch. Implement the feature in a seperate PR.
@brilliant-lx brilliant-lx added the r4r ready for review label Dec 14, 2022
@kyrie-yl kyrie-yl changed the title New batch with size Add NewBatchWithSize API for db and use this API for BloomIndexer.Commit() Dec 14, 2022
brilliant-lx
brilliant-lx previously approved these changes Dec 14, 2022
This change reduces allocations when committing bloombits indexes
by creating the database batch with a larger initial size.
@brilliant-lx brilliant-lx merged commit e9a04cc into bnb-chain:develop Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r4r ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants