Skip to content

Commit c70c69d

Browse files
committed
Add iterative batch building benchmark
1 parent b5c9af4 commit c70c69d

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

op-node/benchmarks/batchbuilding_test.go

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ var (
2828
bc, _ = compressor.NewBlindCompressor(compressor.Config{
2929
TargetOutputSize: 100_000_000_000,
3030
})
31+
realsc, _ = compressor.NewShadowCompressor(compressor.Config{
32+
// this target size was determiend by the devnet sepolia batcher's configuration
33+
TargetOutputSize: 780120,
34+
})
35+
realbc, _ = compressor.NewBlindCompressor(compressor.Config{
36+
// this target size was determiend by the devnet sepolia batcher's configuration
37+
TargetOutputSize: 780120,
38+
})
3139

3240
compressors = map[string]derive.Compressor{
33-
"BlindCompressor": bc,
34-
"NonCompressor": nc,
35-
"RatioCompressor": rc,
36-
"ShadowCompressor": sc,
41+
"BlindCompressor": bc,
42+
"NonCompressor": nc,
43+
"RatioCompressor": rc,
44+
"ShadowCompressor": sc,
45+
"RealBlindCompressor": realbc,
46+
"RealShadowCompressor": realsc,
3747
}
3848

3949
// batch types used in the benchmark
@@ -128,6 +138,53 @@ func BenchmarkFinalBatchChannelOut(b *testing.B) {
128138
}
129139
}
130140

141+
// BenchmarkIncremental fills a channel out incrementally with batches
142+
// each increment is counted as its own benchmark
143+
// Hint: use -benchtime=1x to run the benchmarks for a single iteration
144+
// it is not currently designed to use b.N
145+
func BenchmarkIncremental(b *testing.B) {
146+
chainID := big.NewInt(333)
147+
rng := rand.New(rand.NewSource(0x543331))
148+
// use the real compressor for this benchmark
149+
// use batchCount as the number of batches to add in each benchmark iteration
150+
// and use txPerBatch as the number of transactions per batch
151+
tcs := []BatchingBenchmarkTC{
152+
{derive.SpanBatchType, 100, 1, "RealBlindCompressor"},
153+
{derive.SingularBatchType, 100, 1, "RealShadowCompressor"},
154+
}
155+
for _, tc := range tcs {
156+
cout, err := derive.NewChannelOut(tc.BatchType, compressors[tc.compKey], derive.NewSpanBatch(0, chainID))
157+
if err != nil {
158+
b.Fatal(err)
159+
}
160+
done := false
161+
for base := 0; !done; base += tc.BatchCount {
162+
rangeName := fmt.Sprintf("Incremental %s: %d-%d", tc.String(), base, base+tc.BatchCount)
163+
b.Run(rangeName, func(b *testing.B) {
164+
b.StopTimer()
165+
// prepare the batches
166+
t := time.Now()
167+
batches := make([]*derive.SingularBatch, tc.BatchCount)
168+
for i := 0; i < tc.BatchCount; i++ {
169+
t := t.Add(time.Second)
170+
batches[i] = derive.RandomSingularBatch(rng, tc.txPerBatch, chainID)
171+
// set the timestamp to increase with each batch
172+
// to leverage optimizations in the Batch Linked List
173+
batches[i].Timestamp = uint64(t.Unix())
174+
}
175+
b.StartTimer()
176+
for i := 0; i < tc.BatchCount; i++ {
177+
_, err := cout.AddSingularBatch(batches[i], 0)
178+
if err != nil {
179+
done = true
180+
return
181+
}
182+
}
183+
})
184+
}
185+
}
186+
}
187+
131188
// BenchmarkAllBatchesChannelOut benchmarks the performance of adding singular batches to a channel out
132189
// this exercises the compression and batching logic, as well as any batch-building logic
133190
// Every Compressor in the compressor map is benchmarked for each test case

0 commit comments

Comments
 (0)