You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Fast Buffers have a performance advantage since they are allocated from a single larger buffer. But that means if there is even one byte hanging around, the entire SlowBuffer must hang around in memory. The following is a script that will prove the point:
// WARNING: This script will crash your computer!// ran this with `./out/Release/node --expose-gc mem-test.jsconstSIZE=Buffer.poolSize-2;// if you want to test this w/o crashing your computer, reduce ITTRconstITTR=1e6;varSlowBuffer=require('buffer').SlowBuffer;varstore=[];varrss,tmp,i;rss=process.memoryUsage().rss;for(i=0;i<ITTR;i++){// was using this as a control//tmp = SlowBuffer(SIZE);store.push(Buffer(1));// comment out the following and you'll see that the problem no// longer existstmp=Buffer(SIZE);if(i%1e3===0)gc();}setTimeout(function(){varnr=process.memoryUsage().rssconsole.log(((nr-rss)/1024/1024).toFixed(2));},1000);
Basically every loop will allocate Buffer.poolSize
memory instead of just 1. I'll write an http example later that exhibits the same behavior.