-
Notifications
You must be signed in to change notification settings - Fork 21.5k
core: reduce peak memory usage during reorg #30600
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
Changes from all commits
56011b6
99c0c18
c7b3922
3da0fa5
b0799c2
a6c4273
bcd993a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4231,3 +4231,36 @@ func TestPragueRequests(t *testing.T) { | |
| t.Fatalf("block %d: failed to insert into chain: %v", n, err) | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkReorg(b *testing.B) { | ||
| chainLength := b.N | ||
|
|
||
| dir := b.TempDir() | ||
| db, err := rawdb.NewLevelDBDatabase(dir, 128, 128, "", false) | ||
| if err != nil { | ||
| b.Fatalf("cannot create temporary database: %v", err) | ||
| } | ||
| defer db.Close() | ||
| gspec := &Genesis{ | ||
| Config: params.TestChainConfig, | ||
| Alloc: types.GenesisAlloc{benchRootAddr: {Balance: math.BigPow(2, 254)}}, | ||
| } | ||
| blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil) | ||
| defer blockchain.Stop() | ||
|
|
||
| // Insert an easy and a difficult chain afterwards | ||
| easyBlocks, _ := GenerateChain(params.TestChainConfig, blockchain.GetBlockByHash(blockchain.CurrentBlock().Hash()), ethash.NewFaker(), db, chainLength, genValueTx(50000)) | ||
| diffBlocks, _ := GenerateChain(params.TestChainConfig, blockchain.GetBlockByHash(blockchain.CurrentBlock().Hash()), ethash.NewFaker(), db, chainLength, genValueTx(50000)) | ||
|
||
|
|
||
| if _, err := blockchain.InsertChain(easyBlocks); err != nil { | ||
| b.Fatalf("failed to insert easy chain: %v", err) | ||
| } | ||
| b.ResetTimer() | ||
| if _, err := blockchain.InsertChain(diffBlocks); err != nil { | ||
| b.Fatalf("failed to insert difficult chain: %v", err) | ||
| } | ||
| } | ||
|
|
||
| // Master: BenchmarkReorg-8 10000 899591 ns/op 820154 B/op 1440 allocs/op 1549443072 bytes of heap used | ||
| // WithoutOldChain: BenchmarkReorg-8 10000 1147281 ns/op 943163 B/op 1564 allocs/op 1163870208 bytes of heap used | ||
| // WithoutNewChain: BenchmarkReorg-8 10000 1018922 ns/op 943580 B/op 1564 allocs/op 1171890176 bytes of heap used | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this block. The previous code sent the log removals first, and then the log additions. You changes it so now it sends events for new logs first and them removes old logs.