Skip to main content

Try it Live

Run Hardfork examples in the interactive playground

WASM Implementation

WebAssembly acceleration status for Hardfork operations.

Status: Not Implemented

WASM is NOT implemented for Hardfork operations and is NOT planned.

Why No WASM?

Operations Are Already Optimal

Hardfork provides:
  • Ethereum protocol version enum (constants)
  • Simple comparison operations (array index comparisons)
  • String parsing (hash table lookups)
  • Feature detection (version comparisons)
These operations are:
  • Already optimal in TypeScript
  • Pure O(1) lookups and numeric comparisons
  • No heavy computation or data processing
  • Execution time less than 100ns per operation
WASM overhead (~1-2μs per call) would make operations 10-100x SLOWER.

Performance Characteristics

Pure TypeScript implementation benchmarks: WASM call overhead alone is 1000-2000ns - operations would be 10-100x slower.

When to Use WASM

WASM is beneficial for:
  • Heavy computation (greater than 10μs)
  • Cryptographic operations (hashing, signatures)
  • Large data processing (RLP encoding, ABI encoding)
  • Batch operations (processing many items)
  • CPU-intensive algorithms (complex math, parsing)

WASM Cost-Benefit

Good WASM Candidates

These primitives DO use WASM:
  • Keccak256: ~50μs → ~5μs (10x speedup)
  • secp256k1: ~100μs → ~10μs (10x speedup)
  • RLP encoding: ~10μs → ~1μs (10x speedup)
  • ABI encoding: ~20μs → ~2μs (10x speedup)
These operations are heavy enough that WASM overhead is negligible compared to computation cost.

API Reference

isWasmHardforkAvailable

Check if WASM implementation is available.
Returns: Always false Example:

getHardforkImplementationStatus

Get detailed implementation status.
Returns:
Example:

Import Behavior

hardfork.wasm.js

Usage:

Performance Comparison

TypeScript vs WASM (Hypothetical)

Assuming WASM implemented same logic:

Real-World Impact

Architecture Decision

Why This Matters

Hardfork is a hot path primitive:
  • Called frequently in transaction processing
  • Used in every EVM opcode execution gate
  • Critical for gas calculation
  • Needed for every smart contract call
Performance requirements:
  • Must be less than 100ns per call
  • No allocations
  • Minimal branching
  • Cache-friendly
TypeScript implementation meets all requirements. WASM would violate performance budget.

Design Philosophy

Use the right tool:
  • Simple operations → TypeScript
  • Heavy computation → WASM
  • Critical path → TypeScript (no overhead)
  • Batch processing → WASM (amortize overhead)
Hardfork fits “simple operations” category.

Benchmarking

Running Benchmarks

Typical Results

Interpretation:
  • All operations less than 100ns
  • WASM overhead greater than 1000ns
  • WASM would be 10-100x slower

Alternative Optimizations

Instead of WASM, we optimize through:

1. Constant Folding

2. Hash Table Lookups

3. Inline Comparisons

4. Monomorphic Code

These primitives DO benefit from WASM:

Address

  • Keccak256 hashing for checksums (~10x speedup)
  • Public key derivation (~10x speedup)

Hash

  • Keccak256 implementation (~10x speedup)
  • SHA256 implementation (~8x speedup)

RLP

  • Encoding/decoding large structures (~5-10x speedup)

ABI

  • Encoding/decoding complex types (~5-10x speedup)

secp256k1

  • Signature operations (~10x speedup)
  • Public key recovery (~10x speedup)
Pattern: Heavy computation (greater than 10μs) benefits from WASM. Simple lookups do not.

Best Practices

1. Import from Main Module

2. Don’t Check for WASM

3. Trust the Implementation

Future Considerations

When Would WASM Be Added?

WASM might be considered if:
  1. Hardfork operations become greater than 10μs per call
  2. Batch operations on 1000+ hardforks become common
  3. Heavy computation is added (unlikely for enum operations)
None of these are expected.

Maintaining Zero Overhead

Current design maintains zero overhead:
  • No WASM loading
  • No WASM compilation
  • No WASM call overhead
  • No fallback logic
  • Simpler codebase
This is a feature, not a limitation.