Files
salvium-rs/test/process-worker.js
T
Matt Hess 7730b6993f ● Add AssemblyScript WASM VM for RandomX full mode
- Create assembly/vm.ts with full RandomX VM implementation
    - 256 instructions, 2048 iterations per hash
    - Native u64/f64 operations in WebAssembly
    - Full mode dataset lookups (2GB pre-computed)

  - Update miner to use WASM VM for full mode
    - mining-worker-asm.js uses pre-compiled WASM
    - ~32 H/s per thread (4x faster than light mode)
    - 8 threads achieves ~260 H/s

  - Clean up redundant code
    - Remove mining-worker-full.js (old JIT approach)
    - Consolidate 'asm' mode into 'full' mode
2026-01-18 01:16:10 +00:00

36 lines
899 B
JavaScript

/**
* Child Process Worker for RandomX Hashing
*/
const workerId = parseInt(process.argv[2]);
const hashCount = parseInt(process.argv[3]);
// Dynamic import
const { randomx_init_cache, randomx_create_vm } = await import('../src/randomx/vendor/index.js');
// Initialize
const seedHash = new TextEncoder().encode('test seed');
const cache = randomx_init_cache(seedHash);
const vm = randomx_create_vm(cache);
const template = new Uint8Array(76);
const view = new DataView(template.buffer);
// Signal ready
process.send({ type: 'ready', workerId });
// Wait for start
process.on('message', (msg) => {
if (msg.type === 'start') {
const start = Date.now();
for (let i = 0; i < hashCount; i++) {
view.setUint32(39, i, true);
vm.calculate_hash(template);
}
const elapsed = Date.now() - start;
process.send({ type: 'done', workerId, hashCount, elapsed });
}
});