erigon-pulse/core/state
jack meng d370ea7ac2
fixed bitmap performance when write index (#7986)
Here is my case:

writeIndex function takes about 39% in pprof flame graph. I dive into it
and find out that we use POA consensus, therefore mining addresses have
a big bitmap.

```
func writeIndex(blocknum uint64, changes *historyv2.ChangeSet, bucket string, changeDb kv.RwTx) error {
	buf := bytes.NewBuffer(nil)
	for _, change := range changes.Changes {
		k := dbutils.CompositeKeyWithoutIncarnation(change.Key)
		index, err := bitmapdb.Get64(changeDb, bucket, k, math.MaxUint32, math.MaxUint32)
		if err != nil {
			return fmt.Errorf("find chunk failed: %w", err)
		}
		index.Add(blocknum)
		if err = bitmapdb.WalkChunkWithKeys64(k, index, bitmapdb.ChunkLimit, func(chunkKey []byte, chunk *roaring64.Bitmap) error {
			buf.Reset()
			if _, err = chunk.WriteTo(buf); err != nil {
				return err
			}
			return changeDb.Put(bucket, chunkKey, common.CopyBytes(buf.Bytes()))
		}); err != nil {
			return err
		}
	}
	return nil
}
```
assume that a mining address has a big bitmap (Cardinality 400000), then
"writeIndex" will split it into 300 small bitmaps according to
”ChunkLimit“ and next time "writeIndex" will union all small bitmaps
into a big bitmap, then use binary search to split it into 300 small
bitmaps. over and over again.

I think blockNum > index.Maximum(), so that we only need get the last
one of 300 small bitmaps .

Co-authored-by: mengweifu <75886642@qq.com>
2023-08-13 02:07:43 +06:00
..
contracts Block Gas limit contract integration for Chiado (#7727) 2023-06-19 22:06:51 +05:30
historyv2read e2: avoid do RestoreCodeHash twice (#7706) 2023-06-11 12:28:47 +07:00
temporal e3: idx range method (#7767) 2023-06-20 10:58:37 +07:00
access_list_test.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
access_list.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
cached_reader2.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
cached_reader.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
cached_writer.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
change_set_writer.go e3: move domains to tables.go (#7707) 2023-06-11 21:12:05 +07:00
database_test.go Replaced old version of Engine API with newer version (#7972) 2023-08-05 23:33:10 +02:00
database.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
db_state_reader.go reference hash, address, and chain config from lib (#6536) 2023-01-13 18:12:18 +00:00
db_state_writer.go fixed bitmap performance when write index (#7986) 2023-08-13 02:07:43 +06:00
dump.go e3: move domains to tables.go (#7707) 2023-06-11 21:12:05 +07:00
helper.go
history_reader_inc.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
history_reader_v3.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
history_test.go e3: move domains to tables.go (#7707) 2023-06-11 21:12:05 +07:00
history_walk.go e3: move domains to tables.go (#7707) 2023-06-11 21:12:05 +07:00
intra_block_state_test.go [Devnet tool] Side-quest to improve logging - part 1 (#7445) 2023-05-07 07:28:15 +01:00
intra_block_state.go Implement EIP-6780: SELFDESTRUCT only in same transaction (#7976) 2023-08-06 17:48:11 +02:00
journal.go Implement EIP-1153 transient storage (#7405) 2023-05-01 18:26:24 +02:00
plain_readonly.go e3: move domains to tables.go (#7707) 2023-06-11 21:12:05 +07:00
plain_state_reader.go fix import cycle in tests 2023-04-19 15:41:12 +07:00
plain_state_writer.go Remove excessive logging (#7882) 2023-07-13 00:52:03 +01:00
recon_state.go e3: less conlicts 2023-04-10 09:38:08 +07:00
recon_writer_inc.go enable more linters #954 (#7179) 2023-03-25 05:13:27 +00:00
rw_v3.go fix for test (#7765) 2023-06-20 02:04:42 +01:00
state_object_test.go reference hash, address, and chain config from lib (#6536) 2023-01-13 18:12:18 +00:00
state_object.go Implement EIP-6780: SELFDESTRUCT only in same transaction (#7976) 2023-08-06 17:48:11 +02:00
state_test.go e4: release some tests (#7729) 2023-06-14 10:01:00 +07:00
transient_storage.go Implement EIP-1153 transient storage (#7405) 2023-05-01 18:26:24 +02:00