How reg-cli architecture works
mainThe reg-cli tool uses a hybrid architecture:
- Node.js Host: Handles CLI argument parsing, the
compare()EventEmitter API, and manages worker threads. - Wasm Engine: A
Wasm32-WASIp1-threadsbundle (reg.wasm) that performs the heavy lifting. It is compiled from Rust and uses Rayon for parallel image diffing.
Key Design Choices:
- Portability: The Wasm engine runs identically on Linux, macOS, and Windows without requiring native build tools like
node-gyp. - Sandboxing: File I/O is constrained via WASI preopens, ensuring the Wasm engine only accesses the directories explicitly provided.
- Performance: By using Rust and Rayon inside a WASI thread pool, the engine achieves significant speedups (up to 2.9x for 4K images) compared to pure JS implementations.