Skip to main content
Warp Router implements multiple gas optimization techniques that can reduce operational costs by 20-40% compared to standard routing implementations.

Adapter Caching

One of the most effective optimizations is adapter caching in batch operations. When processing multiple operations with the same adapter, the Router caches the adapter address to avoid repeated storage reads.

How It Works

In RouterLogic.sol:188-280, the optimized routing function implements:

Gas Savings

  • Cold SLOAD: ~2,100 gas per adapter lookup
  • Cache hit: Skips SLOAD entirely
  • Typical savings: 20-40% for batches with repeated adapters
When batching operations, group calls to the same adapter together to maximize cache hits.

Special Selectors

Special selectors bypass the adapter lookup mechanism entirely for common operations, providing even greater gas savings.

Available Special Selectors

singleCall

Executes a single external call directly without adapter overhead. Defined in DirectRoutes.sol:121-127. Gas savings: ~2,600+ gas per call (SLOAD + DELEGATECALL overhead)

multiCall

Batches multiple external calls in a single transaction. Defined in DirectRoutes.sol:128-134. Gas savings: Similar to singleCall, with additional batching efficiency

Fee Collection

In-router fee collection functions process fees without delegatecall:
Defined in DirectRoutes.sol:160-171. Gas savings: ~2,600+ gas + eliminates adapter call overhead

How Special Selectors Work

From DirectRoutes.sol:146-179:

Batch Operations

Optimized Encoding

The optimized_routeFill921336808 function uses encoded calldata to reduce costs:
Benefits:
  • Reduces calldata costs by avoiding array decoding overhead
  • Saves ~200-500 gas per element
  • Assembly-based decoding operates directly on calldata pointers

Assembly Decoding

From RouterLogic.sol:206-221:
This avoids memory copying and operates directly on calldata, saving memory expansion costs.

Solver Context Management

Skip Relayer Context

Adapters can declare they don’t need relayer context using adapter tags:
From IntentExecutorAdapter.sol:227-229. Benefits:
  • Skips array access and bounds checking
  • Prevents unnecessary context consumption tracking
  • Example: IntentExecutorAdapter doesn’t consume relayer context

Context Consumption Tracking

From RouterLogic.sol:261-280:

Packed Calldata Encoding

For approval operations, DirectRoutes uses packed encoding to save calldata costs.

Single Approval

From DirectRoutes.sol:332-368:
Savings: ~76 bytes per approval (~1,200 gas at 16 gas/byte)

Batch Approvals

From DirectRoutes.sol:386-415:

Performance Benchmarks

Based on DirectGasComparison.t.sol test results:

Adapter Caching

20-30% savings for 3+ identical adapter calls

Special Selectors

~2,600 gas saved per direct route

Encoded Calldata

200-500 gas saved per batch element

Packed Encoding

~1,200 gas saved per approval

Best Practices

1

Group by Adapter

Batch operations that use the same adapter together to maximize cache hits
2

Use Special Selectors

For simple calls and fee collection, use special selectors instead of custom adapters
3

Skip Unnecessary Context

If your adapter doesn’t need relayer context, use setSkipRelayerContext() in your adapter tag
4

Use Packed Encoding

For approvals and simple data, prefer packed encoding over ABI encoding
Always benchmark your specific use case. Gas savings vary based on:
  • Number of operations in batch
  • Adapter diversity
  • Storage slot warmth (cold vs warm)
  • Network gas pricing