Raise Chrome JS heap limit?

笑着哭i 提交于 2021-01-27 04:36:51

问题


I have a JavaScript application that uses way too much memory. It doesn't crash out the tab, but it can take minutes to load, most of which is spent in GC. I'm using the heap profiler to see what functions are allocating the most memory, which works great.

Is there some way to get Chrome to allow a larger JS heap per process, so that I can turn around test runs on reducing memory pressure without waiting minutes for GC? A command-line argument I couldn't find, perhaps?


回答1:


Yes the jsHeapSizeLimit reported in the console:

 > console.memory
  MemoryInfo {totalJSHeapSize: 42100000, usedJSHeapSize: 29400000, jsHeapSizeLimit: 1620000000}

is calculated from two limits:

  size_t MaxReserved() {
    return 2 * max_semi_space_size_ + max_old_generation_size_;
  }

chromium source

You may set these maximums (in MB) with v8 flags:

chromium --js-flags="--max_old_space_size=512 --max_semi_space_size=512"

(or you can find the similarly named initial allocation flags with --js-flags=--help if you prefer.)

A short write up of how the gc manages the heap spaces is here.



来源:https://stackoverflow.com/questions/43643406/raise-chrome-js-heap-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!