Skip to main content

Try it Live

Run FeeMarket examples in the interactive playground

FeeMarket WASM

WASM implementation status for fee market calculations.

Status

WASM NOT IMPLEMENTED (and not needed)

Why No WASM?

FeeMarket provides:
  • EIP-1559 and EIP-4844 constants (no computation)
  • Simple bigint arithmetic (base fee, blob fee formulas)
  • Lightweight validation functions
These operations are:
  • Already optimal in TypeScript
  • Too lightweight for WASM overhead to provide benefit
  • Pure calculations with no I/O or complex state
WASM call overhead (~1-2μs) exceeds calculation time (less than 1μs)

Performance Characteristics

Pure TypeScript benchmarks:
WASM overhead:
  • Function call: ~1-2μs
  • Memory copy: Additional overhead for bigint conversions
  • Total: 10-100x slower for these operations
Verdict: TypeScript is 10-100x faster

When WASM Would Help

WASM beneficial for:
  • Heavy computation (greater than 10μs per operation)
  • Cryptographic operations (hashing, signatures, elliptic curve)
  • Large data processing (RLP encoding, ABI encoding)
  • Batch operations (processing thousands of items)
  • CPU-intensive loops
FeeMarket doesn’t fit these criteria:
  • Lightweight bigint math
  • Simple formulas
  • No cryptographic operations
  • Typically single-item operations

Implementation Status

FeeMarket.wasm.ts

Re-exports pure TypeScript implementation:

Usage

Simply use FeeMarket.js directly:
Don’t import from .wasm.js:

Benchmarks

Run benchmarks to verify performance:
Results show TypeScript is optimal:
  • BaseFee: ~4M ops/sec
  • BlobBaseFee: ~100K ops/sec (Taylor series)
  • calculateTxFee: ~20M ops/sec
  • nextState: ~2M ops/sec
See fee-market-bench-results.json for detailed results.

Alternative: Zig Implementation

Fee market calculations implemented in Zig (fee_market.zig) for:
  • Testing compatibility
  • Native performance validation
  • Reference implementation
Zig is NOT faster than TypeScript for these operations:
  • V8 JIT optimizes bigint arithmetic effectively
  • Zig-WASM bridge adds overhead
  • No performance gain for simple calculations
Zig useful for:
  • Native CLI tools
  • Testing against reference implementation
  • Educational purposes

Comparison with Other Primitives

FeeMarket similar to Uint256: pure bigint math, no WASM benefit.

Future Considerations

WASM implementation reconsidered if:
  • Batch operations common (thousands of fee calculations)
  • Integration with other WASM modules (shared memory)
  • Platform with poor bigint performance
Currently: TypeScript optimal for all use cases.

References

Primitives with WASM acceleration: