-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leaks in WASM #352
Comments
I just ruled out that this could be a memory fragmentation on the Rust side. Rust allocates a single continuous memory region my using After an hour or so, browser's task manager was showing 3GB of memory consumption by Lumina tab. However the memory region that was used by Rust was at 103mb, almost from the beginning of the syncing. This concludes that memory leaks are tightly related to JavaScript's types. |
`tracing_web::performance_layer` was causing high memory consumption because browser was keeping high resolution data for each tracing event. Fixes eigerco#352 and eigerco#353
After reading JS Objects in Rust from wasm-bindgen's internal design documentation I ruled out the posibility that memory leak is happening because of Rust not freeing JS objects. I was printing wasm_bindgen::externref_heap_live_count every 1 minute. In case of memory leak, that value should have constantly increasing to a huge number over time, which didn't happen. After ruling out the above, I couldn't understand why memory consumption of Lumina's tab was increasing and even becoming more than 3GB. Throughout all my investigation I was using Allocation instrumentation on timeline of Chrome, trying to pin point the leak. While doing that I was ignoring I started checking random things to find any other clues about the leak, including of reading code of wasm-bindgen generated file imports.wbg.__wbg_mark_6045ef1772587264 = function() { return handleError(function (arg0, arg1, arg2) {
getObject(arg0).mark(getStringFromWasm0(arg1, arg2));
}, arguments) };
imports.wbg.__wbg_mark_bad820680b8580c2 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
getObject(arg0).mark(getStringFromWasm0(arg1, arg2), getObject(arg3));
}, arguments) };
imports.wbg.__wbg_measure_1d846b814d43d7e1 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
getObject(arg0).measure(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getStringFromWasm0(arg5, arg6));
}, arguments) };
imports.wbg.__wbg_measure_7ca0e5cfef892340 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
getObject(arg0).measure(getStringFromWasm0(arg1, arg2), getObject(arg3));
}, arguments) };
imports.wbg.__wbg_performance_72f95fe5952939b5 = function() {
const ret = globalThis.performance;
return addHeapObject(ret);
}; Which indicates that our Rust code at some point is using After doing that, memory consumption stopped increasing to that huge numbers! 🥳 Note that this is not really a memory leak, but it is how performance marks work. |
Currently there are memory leaks in WASM and it looks like a limitation of WASM, but we need further investigation.
Useful information:
about:memory
which shows some extra information about the workerDTD=1 ./firefox
in nightly's directory.wasm-pack
's--weak-refs
and--reference-types
The text was updated successfully, but these errors were encountered: