7730b6993f
- 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
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
/**
|
|
* Test Worker Initialization Time
|
|
*/
|
|
|
|
import { Worker, isMainThread, parentPort, workerData } from 'worker_threads';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
if (!isMainThread) {
|
|
const { workerId } = workerData;
|
|
const startTime = Date.now();
|
|
|
|
parentPort.postMessage({ type: 'started', workerId });
|
|
|
|
// Import the module
|
|
const { randomx_init_cache, randomx_create_vm } = await import('../src/randomx/vendor/index.js');
|
|
parentPort.postMessage({ type: 'imported', workerId, time: Date.now() - startTime });
|
|
|
|
// Initialize cache
|
|
const seedHash = new TextEncoder().encode('test seed');
|
|
const cache = randomx_init_cache(seedHash);
|
|
parentPort.postMessage({ type: 'cache_ready', workerId, time: Date.now() - startTime });
|
|
|
|
// Create VM
|
|
const vm = randomx_create_vm(cache);
|
|
parentPort.postMessage({ type: 'vm_ready', workerId, time: Date.now() - startTime });
|
|
|
|
// Do one hash
|
|
const hash = vm.calculate_hash(new Uint8Array(76));
|
|
parentPort.postMessage({ type: 'hashed', workerId, time: Date.now() - startTime });
|
|
|
|
parentPort.postMessage({ type: 'done', workerId, totalTime: Date.now() - startTime });
|
|
} else {
|
|
async function main() {
|
|
console.log('Worker Initialization Test');
|
|
console.log('==========================\n');
|
|
|
|
const workerPath = fileURLToPath(import.meta.url);
|
|
|
|
const worker = new Worker(workerPath, {
|
|
workerData: { workerId: 0 }
|
|
});
|
|
|
|
worker.on('message', (msg) => {
|
|
console.log(`[${msg.type}] Worker ${msg.workerId}: ${msg.time || msg.totalTime || ''}ms`);
|
|
|
|
if (msg.type === 'done') {
|
|
worker.terminate();
|
|
console.log('\nDone!');
|
|
}
|
|
});
|
|
|
|
worker.on('error', (err) => {
|
|
console.error('Worker error:', err);
|
|
});
|
|
}
|
|
|
|
main().catch(console.error);
|
|
}
|