I used gcs-read node to read a ~50MB file and it took several minutes to read the file stream.
After carefully checking, I found the bottleneck was this line msg.payload = Buffer.concat([msg.payload, data]);.
Every time this line is invoked, it creates a new buffer and does memory copy.
In this PR, with the help of pre-allocating buffer and only copying small data chunk every time, the final total reading time became < 10 seconds.
I used
gcs-read
node to read a ~50MB file and it took several minutes to read the file stream. After carefully checking, I found the bottleneck was this linemsg.payload = Buffer.concat([msg.payload, data]);
. Every time this line is invoked, it creates a new buffer and does memory copy.In this PR, with the help of pre-allocating buffer and only copying small data chunk every time, the final total reading time became
< 10 seconds
.