-
|
So I became very interested in this library after stumbled upon this thread. But I have several questions about the performance concern of spawning a new worker. I have a function as following: import { gzip } from 'fflate';
const gzipStuff = (data) => {
const gzip = new Promise((resolve, reject) => {
const callback = (error: Error, compressed) => {
error ? reject(error) : resolve(compressed);
};
const buffer = Buffer.from(
isDataString ? data : JSON.stringify(data),
'utf-8',
);
// gzip the buffer into an archive
gzip(buffer, callback);
});
return gzip
.then((compressed) => {
// gzip op finished, calculate the end timing
// will be sent to backend
return compressed
})
}This function is repeatedly called by many API call operations, so we can expect several Workers could be spawned at the same time. Then I tried to throttle the CPU to be 6x slower and was quite surprised that this method is ~2x slower than It's also mentioned here: https://nodejs.org/api/worker_threads.html
What could be improved here? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
For some buffers |
Beta Was this translation helpful? Give feedback.
-
|
Related - #58 |
Beta Was this translation helpful? Give feedback.
For some buffers
fflatewill always be substantially slower thanzlib. In this case the overhead of the worker call is probably not the only reasonfflateis slower. However it is probably worth looking into whether a worker pool could be integrated intofflate, I'll do that for the next release.