Hi!
We are developing a browser-based sculpting software. We use C++ and emscripten to compile it to js from the beginning. You can try it free at
www.leopoly.com
However, as the project growing larger and larger, we have to face some "bugs" where the browser crashes (Chrome and FF too). We figured out the the reason might be the large memory usage of the js engine. In the browser the problem arises when we import or export large meshes. In these operations there are lots of memory allocations and deallocations, std container creations, growings and destroys etc. All these happen between two animation frames.
There are some possibilities we think of:
1) The many memory operations fragmentate the large typed array used to simulate the heap, then it needs to grow and grow, then lastly the Js engine runs out of memory.
2) Even if the typed array can "shrink", I think that the browser garbage collector is not working between two animation frames.
What do you suggest, how can we work around this problem? We may use some shared buffers (create custom allocators or something else), may distribute the processing between many frames, but all that will require a lot of work and make the code very ugly and hardly readable. Is there any other tricks? Can emscripten defragment the memory when we need?
Also, there are some other strange things about memory. Sometimes we found that even with low memory usage in JS (we check that in Chrome only with window.performance.use/totalJSHeapSize), the browser memory usage is very large. For example with 60-80 Mbs of JS Heap size the browser normally runs with approx 150 Mb, but sometimes it takes 500 Mb or even 1 Gb. However it's highly browser-implementation specific stuff, but what can explain this?
Thanks,
Endre