@@ -14,6 +14,22 @@ type BatchingStrategy interface {
1414 ShouldSubmit (pendingCount uint64 , totalSize int , maxBlobSize int , timeSinceLastSubmit time.Duration ) bool
1515}
1616
17+ // NewBatchingStrategy creates a batching strategy based on configuration
18+ func NewBatchingStrategy (cfg config.DAConfig ) (BatchingStrategy , error ) {
19+ switch cfg .BatchingStrategy {
20+ case "immediate" :
21+ return & ImmediateStrategy {}, nil
22+ case "size" :
23+ return NewSizeBasedStrategy (cfg .BatchSizeThreshold , cfg .BatchMinItems ), nil
24+ case "time" :
25+ return NewTimeBasedStrategy (cfg .BlockTime .Duration , cfg .BatchMaxDelay .Duration , cfg .BatchMinItems ), nil
26+ case "adaptive" :
27+ return NewAdaptiveStrategy (cfg .BlockTime .Duration , cfg .BatchSizeThreshold , cfg .BatchMaxDelay .Duration , cfg .BatchMinItems ), nil
28+ default :
29+ return nil , fmt .Errorf ("unknown batching strategy: %s" , cfg .BatchingStrategy )
30+ }
31+ }
32+
1733// ImmediateStrategy submits as soon as any items are available
1834type ImmediateStrategy struct {}
1935
@@ -122,22 +138,6 @@ func (s *AdaptiveStrategy) ShouldSubmit(pendingCount uint64, totalSize int, maxB
122138 return false
123139}
124140
125- // NewBatchingStrategy creates a batching strategy based on configuration
126- func NewBatchingStrategy (cfg config.DAConfig ) (BatchingStrategy , error ) {
127- switch cfg .BatchingStrategy {
128- case "immediate" :
129- return & ImmediateStrategy {}, nil
130- case "size" :
131- return NewSizeBasedStrategy (cfg .BatchSizeThreshold , cfg .BatchMinItems ), nil
132- case "time" :
133- return NewTimeBasedStrategy (cfg .BlockTime .Duration , cfg .BatchMaxDelay .Duration , cfg .BatchMinItems ), nil
134- case "adaptive" :
135- return NewAdaptiveStrategy (cfg .BlockTime .Duration , cfg .BatchSizeThreshold , cfg .BatchMaxDelay .Duration , cfg .BatchMinItems ), nil
136- default :
137- return nil , fmt .Errorf ("unknown batching strategy: %s" , cfg .BatchingStrategy )
138- }
139- }
140-
141141// estimateBatchSize estimates the total size of pending items
142142// This is a helper function that can be used by the submitter
143143func estimateBatchSize (marshaled [][]byte ) int {
@@ -180,39 +180,6 @@ func optimizeBatchSize(marshaled [][]byte, maxBlobSize int, targetUtilization fl
180180 return count
181181}
182182
183- // BatchMetrics provides information about batch efficiency
184- type BatchMetrics struct {
185- ItemCount int
186- TotalBytes int
187- MaxBlobBytes int
188- Utilization float64 // percentage of max blob size used
189- EstimatedCost float64 // estimated cost relative to single full blob
190- }
191-
192- // calculateBatchMetrics computes metrics for a batch
193- func calculateBatchMetrics (itemCount int , totalBytes int , maxBlobBytes int ) BatchMetrics {
194- utilization := 0.0
195- if maxBlobBytes > 0 {
196- utilization = float64 (totalBytes ) / float64 (maxBlobBytes )
197- }
198-
199- // Rough cost estimate: each blob submission has a fixed cost
200- // Higher utilization = better cost efficiency
201- estimatedCost := 1.0
202- if utilization > 0 {
203- // If we're only using 50% of the blob, we're paying 2x per byte effectively
204- estimatedCost = 1.0 / utilization
205- }
206-
207- return BatchMetrics {
208- ItemCount : itemCount ,
209- TotalBytes : totalBytes ,
210- MaxBlobBytes : maxBlobBytes ,
211- Utilization : utilization ,
212- EstimatedCost : estimatedCost ,
213- }
214- }
215-
216183// ShouldWaitForMoreItems determines if we should wait for more items
217184// to improve batch efficiency
218185func ShouldWaitForMoreItems (
@@ -239,10 +206,3 @@ func ShouldWaitForMoreItems(
239206
240207 return currentUtilization < minUtilization - epsilon
241208}
242-
243- // BatchingConfig holds configuration for batch optimization
244- type BatchingConfig struct {
245- MaxBlobSize int
246- Strategy BatchingStrategy
247- TargetUtilization float64
248- }
0 commit comments