AssemblyScript lets you write TypeScript-like code that compiles directly to WebAssembly — no Rust knowledge required. In NEX OS, the exported functions inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shadownrx/windows/llms.txt
Use this file to discover all available pages before exploring further.
assembly/index.ts power the Task Manager’s real-time CPU and memory metrics, running calculations at near-native speed while the React UI stays completely responsive. If you already know TypeScript, you can start writing WASM functions immediately.
Exported Functions
Theassembly/index.ts file is the sole source of truth for the AssemblyScript module. The following two functions are exported and available to React components through the useWasmEngine hook and the wasmLoader utility.
calculateLoad takes two f64 arguments — cpu and mem as decimal fractions — and returns a weighted system-impact score. getRank takes that score and maps it to an integer rank (0–3) that the Task Manager uses to colour-code process rows.
AssemblyScript Type System
AssemblyScript is a strict subset of TypeScript with explicit numeric types. These map directly to WebAssembly value types, which is what makes the compilation possible and why the performance is so high.| Category | Types | Notes |
|---|---|---|
| Signed integers | i8, i16, i32, i64 | i32 is the default integer type |
| Unsigned integers | u8, u16, u32, u64 | Use for counts and indices |
| Floats | f32, f64 | f64 matches JavaScript number |
| Arrays | Float64Array, i32[] | Typed arrays cross the WASM boundary |
| Strings | string | Limited support — avoid for exported functions |
Compilation Workflow
Edit assembly/index.ts
Open
assembly/index.ts and add or modify exported functions. Use AssemblyScript types (f64, i32, Float64Array) for all parameters and return values.Run the build command
Compile the AssemblyScript source to WebAssembly using the project’s npm script:This internally calls
asc assembly/index.ts --target release using the configuration in asconfig.json.asconfig.json Configuration
The asconfig.json file at the project root controls how AssemblyScript compiles the module. NEX OS ships with the following configuration:
| Key | Value | Effect |
|---|---|---|
outFile | public/process_utils.wasm | Where the binary is written (both targets) |
optimizeLevel | 3 | Maximum LLVM-level optimizations (release only) |
shrinkLevel | 0 | Size shrinking disabled — preserves readable output |
sourceMap | true | Emits .wasm.map for source-mapped debugging in DevTools |
bindings | "esm" | Emits an ES module wrapper (process_utils.js) for easy import |
The pre-compiled
public/process_utils.wasm is committed to the repository. You only need to run npm run build:as if you modify assembly/index.ts.Consuming the Module in React
The wasmLoader Utility
The low-level loader in src/utils/wasmLoader.ts fetches and instantiates the binary once, then caches the result for all subsequent calls:
The useWasmEngine Hook (Recommended)
For React components, the useWasmEngine hook at src/utils/useWasmEngine.ts is the preferred integration point. It wraps wasmLoader, manages loading state, and provides a transparent JavaScript fallback:
Limitations
Not all TypeScript patterns are valid in AssemblyScript. The compiler enforces strict constraints that map to WebAssembly’s type system.| Pattern | Supported | Notes |
|---|---|---|
Float64Array parameters | ✅ | Efficient cross-boundary transfer |
i32 / f64 return values | ✅ | Map directly to WASM value types |
Primitive types (i32, f64) | ✅ | First-class citizens |
Callbacks (() => void) | ❌ | Function references not exportable |
Complex return objects ({ x, y }) | ❌ | Structs cannot cross the JS boundary |
Dynamic any types | ❌ | AssemblyScript is strictly typed |
Performance Tips
Getting the best out of WASM requires minimising the cost of crossing the JS ↔ WASM boundary. Use precise numeric types:Float64Array views of existing buffers rather than creating new arrays just for a WASM call.
Debugging
Timing WASM vs JavaScript
Inspecting the Binary
calculateLoad and getRank appearing as native frames in the flame chart.