erigon-pulse/core
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
..
allocs Remove the Rinkeby testnet (#7677) 2023-06-07 07:42:36 +02:00
asm enable more linters #954 (#7179) 2023-03-25 05:13:27 +00:00
forkid Schedule Shapella for Gnosis Chain (#7784) 2023-06-22 15:36:07 +02:00
rawdb Replaced old version of Engine API with newer version (#7972) 2023-08-05 23:33:10 +02:00
state fixed bitmap performance when write index (#7986) 2023-08-13 02:07:43 +06:00
systemcontracts Added non root logger to bor.ValidatorSet (#7668) 2023-06-06 10:55:59 +01:00
types Fix CopyTxs for BlobTxWrapper (EIP-4844) (#8002) 2023-08-11 20:30:02 +02:00
vm Implement EIP-6780: SELFDESTRUCT only in same transaction (#7976) 2023-08-06 17:48:11 +02:00
.gitignore Renamed chain => core 2014-12-04 10:28:02 +01:00
block_builder_parameters.go Support engine_forkchoiceUpdatedV3 with ParentBeaconBlockRoot (EIP-4788) (#7969) 2023-08-06 11:54:14 +02:00
block_validator_test.go Update execution-spec-tests to v1.0.1 (#7980) 2023-08-08 15:01:35 +02:00
block_validator.go Simplify miner gas limit post EIP-1559. Default to 30M (#3205) 2022-01-05 16:36:24 +07:00
blockchain.go Call InitializeBlockExecution in SpawnMiningExecStage (EIP-4788) (#7999) 2023-08-11 14:04:53 +02:00
blocks.go reference hash, address, and chain config from lib (#6536) 2023-01-13 18:12:18 +00:00
bor_fee_log.go reference hash, address, and chain config from lib (#6536) 2023-01-13 18:12:18 +00:00
chain_makers.go EIP-4844: Rename "data gas" to "blob gas" (#7937) 2023-07-28 12:12:05 +02:00
error.go EIP-4844: Rename "data gas" to "blob gas" (#7937) 2023-07-28 12:12:05 +02:00
events.go reference hash, address, and chain config from lib (#6536) 2023-01-13 18:12:18 +00:00
evm.go EIP-4844: rename "data hash" to "blob hash" (#7947) 2023-07-31 10:12:53 +02:00
gaspool.go EIP-4844: Rename "data gas" to "blob gas" (#7937) 2023-07-28 12:12:05 +02:00
genesis_test.go Enforce blockReader interface (#7737) 2023-06-15 13:11:51 +07:00
genesis_write.go Update execution-spec-tests to v1.0.1 (#7980) 2023-08-08 15:01:35 +02:00
mkalloc.go Break dependency of ethcfg package to core/consensus/etc... move genesis struct to 'types' package (#7206) 2023-03-29 07:27:06 +00:00
rlp_test.go e3: release chain maker changes (#7787) 2023-06-23 10:07:42 +07:00
skip_analysis.go Remove BSC support in Erigon (step 1) (#7246) 2023-04-03 14:46:21 +00:00
state_processor.go EIP-4844: Rename "data gas" to "blob gas" (#7937) 2023-07-28 12:12:05 +02:00
state_transition.go EIP-4844: rename "data hash" to "blob hash" (#7947) 2023-07-31 10:12:53 +02:00
system_contract_lookup.go Remove BSC support in Erigon (step 1) (#7246) 2023-04-03 14:46:21 +00:00
tx_cacher.go Move ETL to erigon-lib (#2667) 2021-09-12 08:50:17 +01:00