Skip to main content

Try it Live

Run RLP examples in the interactive playground

RLP WASM Implementation

High-performance WebAssembly RLP encoder compiled from Zig for performance-critical operations.

Overview

The WASM implementation provides accelerated RLP encoding methods compiled from Zig. Currently supports encoding operations with significant performance improvements over JavaScript. Features:
  • Fast encoding - Compiled Zig code for maximum performance
  • Memory efficient - Zero-copy operations where possible
  • Type safe - TypeScript bindings with full type safety
  • Drop-in replacement - Compatible with JavaScript API
Currently Available:
  • encodeBytes - Encode byte arrays
  • encodeUint - Encode 256-bit unsigned integers
  • toHex / fromHex - Hex conversion utilities

Setup

WASM module loads automatically when available:

encodeBytes

Encode byte arrays using WASM.

    Performance

    WASM encodeBytes significantly faster than JavaScript:

    encodeUint

    Encode 256-bit unsigned integers.

      encodeUintFromBigInt

      Encode bigint directly to RLP.

        Hex Utilities

        Convert between RLP bytes and hex strings.

          Architecture

          Source: Rlp.zig:1-1489

          Benefits

          Performance:
          • Compiled to optimized WASM bytecode
          • No JIT warmup time
          • Predictable performance characteristics
          Memory:
          • Manual memory management for efficiency
          • Zero-copy operations where possible
          • Minimal allocations
          Safety:
          • Zig’s compile-time safety checks
          • No undefined behavior
          • Bounds checking in debug mode

          When to Use WASM

          Use WASM implementation for: High-throughput encoding:
          Large data structures:
          Performance-critical paths:

          Fallback to JavaScript

          WASM loader handles fallback automatically:

          Limitations

          Current WASM implementation has limitations: No decoding yet:
          No list encoding:
          32-byte constraint for uint:

          Future Enhancements

          Planned WASM features:
          • decode - WASM decoding implementation
          • encodeList - WASM list encoding
          • stream encoding - Streaming encode support
          • parallel encoding - Multi-threaded encoding for large data

          Override Patterns

          Replace JavaScript methods with WASM:
          Or create hybrid encoder: