A client-side data compression utility that demonstrates the performance difference between WebAssembly and JavaScript implementations. This application performs computationally intensive data compression/decompression entirely within the user's browser.
✅ Rust-based WebAssembly compression using the flate2 crate
✅ Pure JavaScript compression using the Pako.js library
✅ Side-by-side performance comparison between Wasm and JS
✅ Client-side file processing - your data never leaves your browser
✅ File upload and download functionality
✅ Compression and decompression capabilities
- Rust (WebAssembly): High-performance compression using
flate2compiled to Wasm - JavaScript: Pure JS implementation using Pako.js for comparison
- React + TypeScript: Modern UI with real-time performance metrics
- Vite: Fast build tool and dev server
To build and run this project, you need:
- Node.js (v18 or higher)
- Rust (latest stable version)
- wasm-pack (for compiling Rust to WebAssembly)
If you don't have Rust installed:
# Windows (PowerShell)
Invoke-WebRequest -Uri https://win.rustup.rs/x86_64 -OutFile rustup-init.exe; .\rustup-init.exe
# macOS/Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shAfter installation, restart your terminal and verify:
rustc --version
cargo --version# Windows (PowerShell)
# iwr https://rustwasm.github.io/wasm-pack/installer/init.ps1 -useb | iex
cargo install wasm-pack
# macOS/Linux
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | shVerify installation:
wasm-pack --version-
Install Node dependencies:
npm install
-
Build the WebAssembly module:
npm run build:wasm
This compiles the Rust code to WebAssembly and generates JavaScript bindings in the
pkg/directory. -
Run the development server:
npm run dev
-
Open your browser to the URL shown (typically
http://localhost:5173)
- Upload a file by clicking the upload area
- Select implementation: Choose between WebAssembly or JavaScript
- Compress or Decompress: Click the desired operation button
- View results: See file sizes and processing time
- Download: Get your processed file
Try both implementations with different file sizes to see the performance difference:
- Small files (<100KB): Minimal difference
- Medium files (100KB-1MB): Wasm starts showing advantages
- Large files (>1MB): Wasm should significantly faster
- Make sure Rust is properly installed:
rustc --version - Make sure you're in the project root directory
- Try running manually:
cd rust && wasm-pack build --target web --out-dir ../pkg
- This is expected before building the Wasm module
- Run
npm run build:wasmfirst - The error will disappear once the
pkg/directory is generated
- Check browser console for errors
- Make sure Pako.js is loaded (check Network tab)
- Ensure the Wasm module initialized properly
.
├── rust/
│ ├── src/
│ │ └── lib.rs # Rust compression functions
│ └── Cargo.toml # Rust dependencies
├── services/
│ └── compressor.ts # Wasm module interface
├── components/
│ ├── FileProcessor.tsx # Main UI component
│ ├── StatCard.tsx # Results display
│ └── icons.tsx # SVG icons
├── pkg/ # Generated Wasm bindings (after build)
├── package.json
└── index.html
npm run buildThis will:
- Build the Rust code to WebAssembly
- Bundle the React application
- Output to the
dist/directory
- Rust code in
rust/src/lib.rsuses theflate2crate for compression wasm-packcompiles Rust to.wasmbinary with JS bindings- The app imports and calls the Wasm functions directly
- Uses Pako.js library (loaded from CDN)
- Pure JavaScript implementation of gzip compression
- Runs in the main thread for comparison
The app measures execution time for both implementations, allowing you to see:
- Processing speed differences
- File size reduction
- Memory efficiency
- Compression Algorithm: Gzip (RFC 1952)
- Rust Crate:
flate2for high-performance compression - JS Library: Pako.js for JavaScript implementation
- Wasm Target:
wasm32-unknown-unknown - Build Tool: wasm-pack with
--target web
- The TypeScript error for the Wasm import is expected before building - it will resolve after running
npm run build:wasm - All file processing happens client-side; no data is sent to any server
- Larger files will show more significant performance differences between implementations
MIT