3 ms·
Out of curiosity, why is malloc 75kb ? That seems like an crazy amount of code (if this after linking and dead code removal for platform specific magic?)
by geokon 2y ago
Out of curiosity, why is malloc 75kb ? That seems like an crazy amount of code (if this after linking and dead code removal for platform specific magic?)
- kvdveer 2y agoMalloc can indeed be implemented in a handful of bytes, but that's nog going to perform well. Doing malloc well is actually quite a bit of work. You need to group allocations by size, manage alignment, request and release pages from the OS/browser implement reallocate, etc. A typical malloc implementation is actually a combination of several different allocation strategies.
- flohofwoe 2y agoThe best solution is to reduce the amount of alloc/free calls in your code, then you can just as well use a slow-and-small allocator like emmalloc since allocator overhead doesn't matter anymore: https://github.com/emscripten-core/emscripten/blob/main/system/lib/emmalloc.c https://github.com/emscripten-core/emscripten/blob/main/syst... (e.g. if memory management overhead shows up in the profiler, the proper solution is not to go looking for a faster general-purpose allocator, but to reduce the amount of calls into the allocator)