Sending buffers to Node.js child processes
Asked Answered
V

0

6

In the browser, it is way faster to send buffers instead of regular arrays. This is done in the following way:

// create data that can be transfered
var myData = [1,3,5,78,1,2,45,6,5,12];
var buffer = new Float64Array(myData.slice());

var worker = new Worker("some_worker.js");

// transfer the buffer
worker.postMessage({buffer: buffer}, [buffer]);

Is there a way to pull off the same trick on child processes for Node.js? Does this speed up communication significantly?

For instance, how would I modify the following script to speed it up:

var cp = require('child_process');
// create data that can be transfered
var myData = [1,3,5,78,1,2,45,6,5,12];

var child = cp.fork('some_worker.js');

// transfer the buffer
child.send(myData);
Voice answered 6/8, 2017 at 15:12 Comment(1)
maybe this can help? github.com/GoogleChrome/sw-precacheRodl

© 2022 - 2024 — McMap. All rights reserved.