延迟垃圾收集?
我正在使用 chrome(我的 mac 的开发版本)。
我查看了页面加载的时间线,发现由于加载页面时发生了一些垃圾收集,存在 150 毫秒的延迟。
这是黄线。
我很好奇是否有任何方法可以阻止这种情况,延迟它,无论如何让我让页面加载得更快?
I'm using chrome (the dev version for my mac).
I was looking at the timeline for my page loading and I saw that there is a 150ms delay due to some garbage collection taking place while loading the page.
It's the yellow line.
I was curious if there's any way to stop this, delay it, whatever so I get the page to load faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据一些评论的内容,这不是 C++ 问题。
当 v8(chrome 中的 javascript 引擎)引擎检测到它应该开始释放代码中不再需要的对象使用的内存时,就会发生垃圾收集。您可以访问 v8 页面,详细了解垃圾收集器的功能做。
您的代码提前进行垃圾收集的原因可能有很多,在这种情况下,我们需要查看您的代码。您是否有很多变量在页面加载时超出范围?
Against the grain of some of the comments, this isn't a C++ issue.
Garbage Collection happens when v8 (the javascript engine in chrome) engine detects that it should start freeing up memory used by objects that are no longer needed in the code. You can visit the v8 page for more information about what the garbage collector does.
There might be lots of reasons why your code is garbage collecting early, and in that case we would need to see your code. Do you have a lot of variables that go out of scope at page load?
不要创建太多垃圾:查看 JavaScript 程序在加载期间分配内存的位置,看看是否可以通过重用数据结构或将工作延迟到页面加载后来消除垃圾收集。这可以让你“延迟”垃圾收集。
Don't create so much garbage: Look at where your JavaScript program allocates memory during load and see if you can eliminate the garbage collection by reusing data structures or delaying that work until after the page has loaded. This lets you 'delay' garbage collection.