How to reduce memory size when using SpiderMonkey

He everyone,
I have a proglem here, can somebody help me?

When I use Spidermonkey as Javascript engineer, I find the virtual memory is very huge. It needs extra 2G+ bytes memory. Is there any setting to reduce the memory allocation?

I checked with gdb info proc mappings, there is 2G bytes memory segment ahead of “code” segment. What is it?

Thx

Virtual memory is a promise of the system that some memory pages might be mapped into existence if they are ever accessed.

For security reasons, the JIT reserves pages early to be later used to store executable code which is dynamically created during the execution, and avoid mixing these segments of code in the middle of any other allocations which might be easier to control by attackers.

What you should be looking at, when checking for memory consumption of applications, is the resident memory and / or resident-and-shared memory consumption of programs.

To answer your question more specifically, there is no runtime settings to reduce the size of the JIT memory. This value is hard-coded in the binary.

1 Like

It is possible that you are using a compiler-generated debug version of Spidermonkey which increases the memory usage. Try using the release version instead and see if that helps to reduce the memory allocation. Additionally, you can try using a profiler to identify which parts of your code are using the most memory and see if there are any optimizations or changes you can make to reduce the memory usage.

The 2G+ allocation disappears after compile with “–disable-jit”.
Thanks