See performance through a new lens
A high-performance web application that benchmarks WebAssembly vs JavaScript image processing algorithms in real-time using your webcam feed.
- ๐ฅ Real-Time Video Processing - Live webcam feed with instant filter application
- โก Multi-Threading - Rayon-based parallelization in WebAssembly for 2-5x speedup
- ๐ Performance Visualization - Real-time FPS and processing time graphs
- ๐จ Modern UI - Glassmorphism design with smooth animations
- โจ๏ธ Keyboard Shortcuts - Quick access to all features
- ๐ผ๏ธ Split-Screen Comparison - Side-by-side original vs processed view
- ๐พ Export Functionality - Download frames and benchmark data
- ๐ช Preset Filters - Sharpen, Emboss, Edge Enhance, and Custom Kernels
- Gaussian Blur - Adjustable blur intensity (ฯ: 0.5-5.0)
- Sobel Edge Detection - Real-time edge highlighting
- Custom Kernel Convolution - 3x3 matrix with live editing
- Rust (nightly) - Required for WebAssembly compilation
- wasm-pack - WebAssembly build tool
- Node.js (optional) - For alternative dev servers
- Modern Browser - Chrome/Edge with WebAssembly support
git clone https://github.com/yourusername/prism.git
cd prismrustup toolchain install nightly
rustup default nightly
rustup component add rust-src
rustup target add wasm32-unknown-unknowncargo install wasm-packcd wasm-lib
wasm-pack build --target web --out-dir ../client/pkg . -- -Zbuild-std="panic_abort,std"
cd ..cd server
cargo run --releaseNavigate to http://127.0.0.1:8080
- Click โถ Start Webcam to begin
- Grant webcam permissions when prompted
- Select an algorithm from the dropdown
- Adjust settings using sliders and toggles
| Key | Action |
|---|---|
Space |
Play/Pause webcam |
F |
Toggle fullscreen |
R |
Toggle race mode (JS vs Wasm) |
S |
Toggle split view |
Compare JavaScript and WebAssembly performance side-by-side:
- Enable Race Mode checkbox
- Both implementations run simultaneously
- View speedup factor in real-time
- Export benchmark data for analysis
Quick-access filters for instant effects:
- ๐ช Sharpen - Enhance image edges
- ๐จ Emboss - 3D embossed effect
- โจ Edge Enhance - Subtle edge highlighting
- ๐ Reset - Identity kernel
- ๐ท Save Frame - Download current processed frame as PNG
- ๐ Export Data - Download benchmark results as JSON
prism/
โโโ client/ # Frontend application
โ โโโ index.html # Main HTML file
โ โโโ style.css # Glassmorphism styling (600+ lines)
โ โโโ app.jsx # React component (550+ lines)
โ โโโ jsAlgorithms.js # JavaScript implementations
โ โโโ pkg/ # Compiled WebAssembly module
โโโ wasm-lib/ # Rust/WebAssembly library
โ โโโ src/
โ โ โโโ lib.rs # Image processing algorithms
โ โโโ Cargo.toml # Dependencies (rayon, wasm-bindgen)
โ โโโ rust-toolchain.toml # Nightly Rust config
โ โโโ .cargo/
โ โโโ config.toml # Threading build flags
โโโ server/ # Actix-web server
โโโ src/
โ โโโ main.rs # Server with COOP/COEP headers
โโโ Cargo.toml
The Rust code uses the image crate and rayon for parallel processing:
// Sobel edge detection with Rayon parallelization
result.par_chunks_mut((width * 4) as usize)
.enumerate()
.for_each(|(y, row)| {
// Process each row in parallel
for x in 1..width-1 {
// Sobel kernel calculation
}
});Pure JavaScript implementations for baseline comparison:
function jsGaussianBlur(data, width, height, sigma) {
// Separable 2D Gaussian convolution
// Horizontal and vertical passes
}- Rayon provides work-stealing parallelism
- Threading Flags: Compiled with
atomics,bulk-memory,mutable-globals - Build Command:
-Zbuild-stdrebuilds standard library with threading support
Typical performance improvements (WebAssembly vs JavaScript):
| Algorithm | Speedup | Notes |
|---|---|---|
| Gaussian Blur | 2-4x | Depends on sigma value |
| Sobel Edge | 3-5x | Rayon parallelization shines |
| Custom Kernel | 2-4x | Multi-threaded convolution |
Tested on: Intel i7 (8 cores), Chrome 120+
- Glassmorphism effects with backdrop blur
- Gradient accents (cyan/purple theme)
- Smooth animations on all interactions
- Responsive layout for mobile/desktop
- Real-time FPS chart (60 frames)
- Processing time visualization
- Average/current metrics
- Tooltips on all controls
- Loading states with spinner animations
- Error handling with clear messages
- Debounced inputs for smooth performance
- Zero-Copy Data Handling - Direct buffer manipulation
- Debounced Sliders - 100ms delay reduces overhead
- Canvas Context Options -
willReadFrequently: true - RequestAnimationFrame - Smooth 60 FPS loop
- Rayon Par-Iter - CPU core-level parallelization
- All video processing happens locally in your browser
- No data is sent to any server
- Webcam access requires explicit permission
- HTTPS/localhost required for webcam API
| Browser | Support | Notes |
|---|---|---|
| Chrome 90+ | โ | Full support |
| Edge 90+ | โ | Full support |
| Firefox 89+ | โ | May need COOP/COEP config |
| Safari 15+ | Limited threading support |
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Safari may have limited WebAssembly threading support
- Firefox requires specific COOP/COEP header configuration
- Mobile browsers may have reduced performance
- WebAssembly SIMD - 8x faster pixel operations
- OffscreenCanvas - Worker-thread rendering
- Video Recording - Download processed video clips
- Additional Filters - Median, Canny Edge, Bilateral
- Service Worker - Offline support and caching
- Rust Team - For amazing WebAssembly support
- Rayon - For effortless parallelization
- wasm-bindgen - For seamless JS/Wasm interop
- Actix-web - For the lightweight server
โญ Star this repo if you find it useful!
Built with โค๏ธ using Rust ๐ฆ and WebAssembly ๐ธ๏ธ