Enhanced WebAssembly implementation of Intel oneTBB (Threading Building Blocks) with Deno-first TypeScript wrapper and advanced threading coordination.
- π§΅ Enhanced Threading: Addresses Intel's WASM limitations with pthreads + Web Workers
- π¦ Deno-First: Modern TypeScript wrapper with async/await APIs
- π¦ Production Build System: SIDE_MODULE + MAIN_MODULE variants for optimal deployment
- π§ Worker Coordination: Advanced threading patterns beyond basic pthreads
- β‘ SIMD Ready: Users can implement SIMD within their parallel function bodies
- π Broad Compatibility: Works on all modern browsers with WASM support
# Run demo
deno task demo
# Run tests and benchmarks
deno task test
deno task benchnpm install @discere-os/onetbb.wasmimport OneTBB from '@discere-os/onetbb.wasm';
const tbb = new OneTBB({ numThreads: 4, usePthreads: true });
await tbb.initialize();
const data = new Float64Array(1000000);
for (let i = 0; i < data.length; i++) {
data[i] = Math.random();
}
// Parallel computation
await tbb.parallelFor(0, data.length, (begin, end) => {
for (let i = begin; i < end; i++) {
data[i] = Math.sqrt(data[i]) * 2.0;
}
}, undefined, { grainSize: 10000, useSIMD: true });
tbb.cleanup();const sum = await tbb.parallelReduce(
0, data.length,
0.0, // identity value
(begin, end, partialSum) => {
for (let i = begin; i < end; i++) {
(partialSum as any) += data[i];
}
},
(left, right) => (left as number) + (right as number) // join function
);
console.log(`Sum: ${sum}`);// Users can implement SIMD within their parallel functions if desired
await tbb.parallelFor(0, data.length, (begin, end) => {
// User's choice to use SIMD here with wasm_simd128.h
for (let i = begin; i < end; i++) {
data[i] = Math.sqrt(data[i]) * 2.0;
}
});Benchmark results on modern hardware (Chrome 113+):
| Algorithm | Serial | Threading | Speedup |
|---|---|---|---|
| Array Processing (1M) | 85ms | 24ms | 3.5x |
| Monte Carlo Pi (1M samples) | 180ms | 52ms | 3.5x |
| Parallel Reduce Sum (500K) | 45ms | 14ms | 3.2x |
Note: Users can achieve additional SIMD speedups by implementing SIMD within their function bodies.
| Browser | Version | Threading | Status |
|---|---|---|---|
| Chrome | 88+ | β | Full Support |
| Edge | 88+ | β | Full Support |
| Chrome Android | 88+ | β | Full Support |
| Firefox | 89+ | β | Full Support |
| Safari | 15.2+ | Limited Threading |
Requirements: Basic WASM support (universal). Threading requires SharedArrayBuffer (secure context + COOP/COEP headers).
- Emscripten pthreads: Native pthread support with SharedArrayBuffer
- Web Workers: Dedicated workers for non-pthread operations
- SharedWorker: Cross-tab coordination and shared state
- Worker Pool: Advanced load balancing and work stealing
- WASM SIMD128: Available for users within their parallel function bodies
- No Abstractions: Users have full control over SIMD usage
- Standard APIs: Pure oneTBB parallel_for/parallel_reduce semantics
# Install Emscripten
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk && ./emsdk install latest && ./emsdk activate latest
source ./emsdk_env.sh
# Install Deno
curl -fsSL https://deno.land/install.sh | shdeno task build:wasm # Build all variants
deno task build:side # Production SIDE_MODULE
deno task build:main # Testing MAIN_MODULE
deno task build:threads # Threading-enabledclass OneTBB {
constructor(options?: OneTBBOptions);
async initialize(): Promise<void>;
cleanup(): void;
// Parallel algorithms
async parallelFor<T>(...): Promise<void>;
async parallelReduce<T, R>(...): Promise<R>;
// Capabilities
hasCapability(cap: 'pthreads'|'shared-memory'): boolean;
getVersion(): string;
async getPerformanceStats(): Promise<TBBPerformanceStats>;
}This builds upon Intel's oneAPI Threading Building Blocks (oneTBB), which already includes official WASM support via Emscripten. Our enhancements specifically address the limitations noted in Intel's WASM_Support.md:
π― Addresses Intel's Known WASM Limitations:
- Nested Web Worker Issues: Implements
PROXY_TO_PTHREADand thread pool warm-up solutions - Serial Execution Problem: Provides Worker coordination to prevent unexpected serial behavior
- Performance Optimization: Pre-warmed thread pools and optimal grain size calculation
π Additional Enhancements:
- Deno-first TypeScript wrapper with modern async/await APIs
- Advanced Worker management with load balancing and work stealing
- Production-ready build system with SIDE_MODULE/MAIN_MODULE variants
- Comprehensive testing and benchmarking for web environments
- Standard oneTBB APIs - no custom abstractions, pure Intel TBB semantics
Upstream oneTBB: https://github.com/uxlfoundation/oneTBB
Documentation: https://oneapi-src.github.io/oneTBB/
Intel's WASM Support: See WASM_Support.md for official implementation details
This enhanced WebAssembly implementation is part of a larger effort to bring professional desktop applications to browsers with native performance.
π¨βπ» About the Maintainer: Isaac Johnston (@superstructor) - Building foundational browser-native computing infrastructure through systematic C/C++ to WebAssembly porting.
π Impact: 70+ open source WASM libraries enabling professional applications like Blender, GIMP, and scientific computing tools to run natively in browsers.
π Your Support Enables:
- Continued maintenance and updates
- Performance optimizations
- New library ports and integrations
- Documentation and tutorials
- Cross-browser compatibility testing
π Sponsor this work to help build the future of browser-native computing.