Is there any way to explicitly disable GC runs (at least most time-consuming ones, like GC interrupts in old space) during the specified period of time, while executing some code sensitive to delays? Something like this:
disableGc();
runCodeWithoutDelays();
enableGc();
Probably using some node options, or native modules? Or can I write my own module, is there an API in V8 for that?
Is there any way to explicitly disable GC runs (at least most time-consuming ones, like GC interrupts in old space) during the specified period of time, while executing some code sensitive to delays? Something like this:
disableGc();
runCodeWithoutDelays();
enableGc();
Probably using some node options, or native modules? Or can I write my own module, is there an API in V8 for that?
Share Improve this question edited Feb 15, 2017 at 8:39 artch asked Oct 29, 2015 at 7:13 artchartch 4,5452 gold badges30 silver badges35 bronze badges 9- Hmmm, will this work for you? – thefourtheye Commented Oct 29, 2015 at 7:43
- Not really. This will trigger non-incremental major GC runs (mark-sweep-pact) which are pretty heavy and introduce long delays in parison to fast incremental runs. Rather than running GC myself, I'd like to block GC for some time and release it again to normal operation. – artch Commented Oct 29, 2015 at 14:17
- I would remend raising this question as a bug in Node.js repo and v8 mailing list. – thefourtheye Commented Oct 29, 2015 at 17:26
- I have the same problem. Have you found a solution? – Petr Peller Commented Jan 30, 2017 at 22:36
- Question, do you need to allocate memory during that time? – Mouna Apperson Commented Feb 13, 2017 at 18:31
2 Answers
Reset to default 5 +100As far as I know you can't manually stop v8's garbage collector, the only thing you can do is start the gc process manually running global.gc()
but not stopping v8's process.
Another person had the same question and published an issue on GitHub here: https://github./nodejs/help/issues/462
Answer is you can't disable the GC in Node, but you can at least tweak the memory options to use the max space available and delay GC, by using --max_old_space_size, --max-semi-space-size.
An example is provided there in context.