How wasilibs/go-re2 works
Main Components
a) Core Components:
• Regular Expression Engine Interface (re2.go)
• WebAssembly Implementation Layer
• CGO Implementation Layer
• Internal RE2 Bridge Components
b) Integration Points:
• Standard Library Compatibility Layer
• WebAssembly Runtime (wazero)
• Native RE2 Library Interface
┌─ Application Layer ─────────────────────────┐
• (Client Code using regexp-compatible API) │
• ┬───────────────────────┬─┘
┌─ API Layer ───────┴───────────────────────┴─┐
• re2.go (Public API) │
• ┬───────────────────────┬─┘
┌─ Implementation ──┴───────────┐ ┌─────────┴─┐
• WebAssembly (Default) │ │ CGO │
• ┌─────────────────────────┐ │ │ (Optional)│
• wazero runtime │ │ └───────┬───┘
• ┬──────────────┘ │ │
• ┌──────────┴──────────────┐ │ ┌───────┴───┐
• re2.wasm module │ │ │ Native RE2│
• ┘ │ │ Library │
• ┬─┘ └───────────┘
┌─ Internal Bridge ──────────┴─────────────────┐
• internal/re2_wazero.go │
• internal/re2_re2_cgo.go │
• internal/cre2/ │
• ┬──┘
┌─ Core RE2 Engine ────────────────────────┴──┐
• (C++ RE2 Library - Compiled to WASM/Native) │
• ┬──┘
Additional Elements
• Performance characteristics notes
• Version compatibility information
• Build configuration options
Implementation Details to Note
• Memory management boundaries
• Thread safety considerations
• API compatibility points with stdlib
Optimization Notes
• RE2's special optimizations for different regex patterns
• Parallel execution paths
• Where performance gains occur for large inputs
Integration points with the Go ecosystem
This design captures both the architectural complexity and the performance characteristics that make go-re2 unique, especially its ability to handle complex patterns and large inputs more efficiently than the standard library.