Skip to content

Commit

Permalink
core: preallocate batch size in bloomIndexer (ethereum#25289)
Browse files Browse the repository at this point in the history
This change reduces allocations when committing bloombits indexes
by creating the database batch with a larger initial size.
  • Loading branch information
dbadoy authored and brilliant-lx committed Dec 16, 2022
1 parent da977e9 commit e9a04cc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/bloom_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (b *BloomIndexer) Process(ctx context.Context, header *types.Header) error
// Commit implements core.ChainIndexerBackend, finalizing the bloom section and
// writing it out into the database.
func (b *BloomIndexer) Commit() error {
batch := b.db.NewBatch()
batch := b.db.NewBatchWithSize((int(b.size) / 8) * types.BloomBitLength)
for i := 0; i < types.BloomBitLength; i++ {
bits, err := b.gen.Bitset(uint(i))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/rawdb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (t *table) DiffStore() ethdb.KeyValueStore {
func (t *table) SetDiffStore(diff ethdb.KeyValueStore) {
panic("not implement")
}

// NewBatchWithSize creates a write-only database batch with pre-allocated buffer.
func (t *table) NewBatchWithSize(size int) ethdb.Batch {
return &tableBatch{t.db.NewBatchWithSize(size), t.prefix}
Expand Down

0 comments on commit e9a04cc

Please sign in to comment.