-
Notifications
You must be signed in to change notification settings - Fork 741
Optimize platformvm mempool peek operations (~20% less memory) #1455
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
Conversation
Signed-off-by: Gyuho Lee <gyuho.lee@avalabs.org>
Signed-off-by: Gyuho Lee <gyuho.lee@avalabs.org>
cat /tmp/cpu.before.txt cat /tmp/cpu.after.txt cat /tmp/mem.before.txt cat /tmp/mem.after.txt goos: darwin goarch: arm64 pkg: github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool BenchmarkPeekTxs-12 486460 2414 ns/op PASS ok github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool 1.456s goos: darwin goarch: arm64 pkg: github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool BenchmarkPeekTxs-12 627082 1849 ns/op PASS ok github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool 1.414s goos: darwin goarch: arm64 pkg: github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool BenchmarkPeekTxs-12 479960 2340 ns/op 13568 B/op 3 allocs/op PASS ok github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool 1.383s goos: darwin goarch: arm64 pkg: github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool BenchmarkPeekTxs-12 659138 1806 ns/op 10240 B/op 3 allocs/op PASS ok github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool 1.463s Signed-off-by: Gyuho Lee <gyuho.lee@avalabs.org>
Signed-off-by: Gyuho Lee <gyuho.lee@avalabs.org>
For benchmarks, you can just reproduce with commenting out/in the following: func (m *mempool) PeekTxs(maxTxsBytes int) []*txs.Tx {
// txs := m.unissuedDecisionTxs.List()
// txs = append(txs, m.unissuedStakerTxs.List()...)
// size := 0
// for i, tx := range txs {
// size += len(tx.Bytes())
// if size > maxTxsBytes {
// return txs[:i]
// }
// }
// return txs
txs, remaining := m.unissuedDecisionTxs.ListWithLimit(maxTxsBytes)
if remaining <= 0 {
return txs
}
txs2, _ := m.unissuedStakerTxs.ListWithLimit(remaining)
return append(txs, txs2...)
} |
Signed-off-by: Gyuho Lee <gyuho.lee@avalabs.org>
@@ -36,12 +36,12 @@ var ( | |||
// $ go test -run=NONE -bench=BenchmarkMarshalVersion > /tmp/cpu.before.txt | |||
// $ USE_BUILDER=true go test -run=NONE -bench=BenchmarkMarshalVersion > /tmp/cpu.after.txt | |||
// $ benchcmp /tmp/cpu.before.txt /tmp/cpu.after.txt | |||
// $ benchstat -alpha 0.03 -geomean /tmp/cpu.before.txt /tmp/cpu.after.txt |
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.
This flag is deprecated btw
vms/platformvm/txs/txheap/heap.go
Outdated
@@ -15,7 +15,15 @@ var _ Heap = (*txHeap)(nil) | |||
type Heap interface { | |||
Add(tx *txs.Tx) | |||
Get(txID ids.ID) *txs.Tx | |||
|
|||
// Returns all the transactions in the order of heap. |
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.
as I mentioned above, I'd drop List and keep only ListWithLimit
Signed-off-by: Gyuho Lee <gyuho.lee@avalabs.org>
Discussed offline with @StephenButtolph for other great suggestions. To be updated. |
Seems 1536 is replacing this - so closing. |
Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
Why this should be merged
Simplify, optimize platform vm mempool peek operations.
How this works
Previously, we just list and append all txs, and then iterate one by one with the max tx size limit. This PR introduces listing with limit at the heap level.
How this was tested
Benchmarks + unit tests.