I'm porting a mathematical modelling library, compiled from C and C++ code, to WebAssembly. The test harness for it is also written in C and C++, and is quite complex; replacing it is far too big a job to be considered. C is a large majority of the code, both in the library and in the test harness. I'm compiling for 32-bit; I have one other 32-bit platform, Windows on x86 with 32-bit addressing, but all my other platforms are 64-bit.
I have some test cases that need too much RAM for 32-bit addressing, so those are not run on 32-bit platforms. But I have about a dozen test cases that work on 32-bit Windows but run out of memory on WebAssembly. This is out of about 130,000 tests, so it isn't a big problem, but it does seem that something is using memory less efficiently under WebAssembly than under Windows. We run 32-bit Windows testing under 64-bit Windows, which provides almost 4GB of address space to 32-bit processes, if you pull the right levers, and we do that.
When I look at my Node.js processes that are running my tests, they tend to be using about 13GB of address space, with about 3.5GB resident.
Given those two things, I'm wondering if something about memory growth isn't being handled efficiently, and I should change my linking flags or my command-line arguments to node?
I link with:
-sMAXIMUM_MEMORY=4000MB -sALLOW_MEMORY_GROWTH \
-sINITIAL_MEMORY=256MB -sSTACK_SIZE=64MB \
-sSUPPORT_LONGJMP=1 -sDEFAULT_PTHREAD_STACK_SIZE=1MB \
-sNO_DISABLE_EXCEPTION_CATCHING \
-sEMULATE_FUNCTION_POINTER_CASTS=1 \
-sBINARYEN_EXTRA_PASSES=--pass-arg=max-func-params@55
My Node.js startup options are:
--max-old-space-size=4000 --stack-size=16384 --stack-trace-limit=20
Should I increase INITIAL_MEMORY to 4000MB? Something else?
I'm well aware that one can't get nearly that much memory in a browser. This is about showing that the WebAssembly build can pass the same tests as the native code platforms.
Thanks in advance,
John Dallman