Skip to main content
Source: batch.ts • Tests: batch.test.ts
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Batch Processing

Automatically batch similar operations for efficiency. Essential for optimizing RPC calls, reducing network overhead, and managing concurrent operations in Ethereum applications.

Overview

Two batching strategies:
  • BatchQueue: Automatically batch similar operations by size and time
  • AsyncQueue: Process operations with concurrency limit

BatchQueue

Automatically batch items when:
  • Batch size reaches maxBatchSize
  • maxWaitTime elapses since first item added
All items eventually processed, results returned individually.

Basic Usage

Configuration

createBatchedFunction

Create batched version of function:

AsyncQueue

Process items with concurrency limit.

Basic Usage

Monitor Queue

Real-World Examples

Batch Balance Lookups

Efficiently fetch multiple balances:

Batch Contract Calls

Batch eth_call operations:

Rate-Limited Batching

Combine batching with rate limiting:

Concurrency-Limited Processing

Process items with max concurrency:

Error Handling

Handle batch errors gracefully:

Heterogeneous Batching

Batch different operations:

Manual Queue Control

Flush Queue

Force immediate processing:

Check Queue Size

Clear Queue

Wait for Completion

Batching Strategies

Time-Based Batching

Batch by time window:

Size-Based Batching

Batch by size:

Hybrid Batching

Balance time and size:

Performance Considerations

Batch Size

  • Too small: More overhead, less benefit
  • Too large: Higher latency, memory usage
  • Optimal: 20-100 items for most RPC calls

Wait Time

  • Too short: Small batches, less efficient
  • Too long: High latency for users
  • Optimal: 50-200ms for most applications

Concurrency

  • Too low: Underutilized resources
  • Too high: Rate limiting, resource exhaustion
  • Optimal: 3-10 concurrent operations

Combining with Other Utils

Batch + Rate Limit

Batch + Retry

Batch + Timeout

Best Practices

Choose Appropriate Batch Sizes

  • Balance lookups: 50-100 addresses
  • Contract calls: 20-50 calls
  • Transaction submission: 5-10 transactions
  • Log queries: 10-20 queries

Monitor Queue Performance

Handle Partial Failures

API Reference

BatchQueue

createBatchedFunction

AsyncQueue

See Also