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
We use mimalloc in Bun and locally testing mimalloc dev3 in several of our benchmarks yielded a positive result which is exciting, but a handful of our memory leak stress tests in CI regress. I'm mostly filing this issue so you have another data point for the v3 branch - not asking you to fix a bug or anything. We will stick to v2 for now but will give v3 another go in the future.
This particular test - bun-serve-static.test.ts makes many HTTP requests that respond with a large amount of data, repeatedly appending to a buffer internally (the .body getter forces it to stream internally). HTTP requests are processed in a dedicated thread with it's own mimalloc heap. The main thread receives chunks of the HTTP response from the HTTP thread and appends to an internal buffer (which uses mi_malloc instead of the heap-specific methods).
Note that the calls to Bun.gc() internally call mi_collect(0)
test.each(["arrayBuffer","blob","bytes","text"])("%s",asyncmethod=>{constbyteSize=static_responses[path][method]?.size;constbytes=method==="blob" ? static_responses[path] : awaitstatic_responses[path][method]();// macOS limits backlog to 128.// When we do the big request, reduce number of connections but increase number of iterationsconstbatchSize=Math.ceil((byteSize>1024*1024 ? 48 : 64)/(isWindows ? 8 : 1));constiterations=Math.ceil((byteSize>1024*1024 ? 10 : 12)/(isWindows ? 8 : 1));asyncfunctioniterate(){letarray=newArray(batchSize);constroute=`${server.url}${path.substring(1)}`;for(leti=0;i<batchSize;i++){array[i]=fetch(route).then(res=>{expect(res.status).toBe(200);expect(res.url).toBe(route);if(label==="access .body"){res.body;}returnres[method]();}).then(output=>{expect(output).toStrictEqual(bytes);});}awaitPromise.all(array);Bun.gc();}for(leti=0;i<iterations;i++){awaititerate();}Bun.gc(true);constbaseline=(process.memoryUsage.rss()/1024/1024)|0;letlastRSS=baseline;console.log("Start RSS",baseline);for(leti=0;i<iterations;i++){awaititerate();constrss=(process.memoryUsage.rss()/1024/1024)|0;if(lastRSS+50<rss){console.log("RSS Growth",rss-lastRSS);}lastRSS=rss;}Bun.gc(true);constrss=(process.memoryUsage.rss()/1024/1024)|0;expect(rss).toBeLessThan(4092);constdelta=rss-baseline;console.log("Final RSS",rss);console.log("Delta RSS",delta);},40*1000,);});
The text was updated successfully, but these errors were encountered:
Thanks -- and nice project! This is interesting as I believe that v3 should always use less memory than v2. Is this the latest dev3 (as there have been a bunch of important bug fixes) ?
Does this happen too if you call mi_collect(true) just before getting the rss ?
(Also, if you can give me a way to repro locally without too much hassle that would be give me way to test further -- but no worries if this is not so easy)
We use mimalloc in Bun and locally testing mimalloc
dev3
in several of our benchmarks yielded a positive result which is exciting, but a handful of our memory leak stress tests in CI regress. I'm mostly filing this issue so you have another data point for the v3 branch - not asking you to fix a bug or anything. We will stick to v2 for now but will give v3 another go in the future.Logs from this test:
https://buildkite.com/bun/bun/builds/11698#01950e27-d67a-40a6-b4ec-e381cd978a17
This particular test -
bun-serve-static.test.ts
makes many HTTP requests that respond with a large amount of data, repeatedly appending to a buffer internally (the.body
getter forces it to stream internally). HTTP requests are processed in a dedicated thread with it's own mimalloc heap. The main thread receives chunks of the HTTP response from the HTTP thread and appends to an internal buffer (which usesmi_malloc
instead of the heap-specific methods).Note that the calls to
Bun.gc()
internally callmi_collect(0)
The text was updated successfully, but these errors were encountered: