Chrome DevTools内存不一致 [英] Chrome DevTools Memory Inconsistency

查看:78
本文介绍了Chrome DevTools内存不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用运行速度为60 FPS的JavaScript构建游戏,并且注意到发生了大量的垃圾回收(每1.5秒7.2 MB,请参阅Chrome DevTools,以下),这对帧速率有明显的影响.

我已经使用分配时间表来查看每帧要添加到内存中的内容.如下所示,每个帧分配有4.1 kB.因此,我希望每1.5秒看到369 kB垃圾收集.

为什么两者之间存在数量级差异?我一直在使用分配时间轴"来减少所使用的内存(本来是每帧18 kB).但是,在效果"标签上,这几乎没有影响.

由于分配时间表似乎不正确,是否有任何方法可以知道正在收集的垃圾是什么?

其他信息

  • 这是游戏中两个时刻之间的堆快照比较.这似乎也不是一贯的,它包含了很多我希望每一帧都不会改变的东西.

  • 我尝试删除了游戏中的对象数量(在数组中),这确实对性能"选项卡产生了很大的影响.但我真的很想在DevTools中看到该数组,以便我对其进行优化.

  • 我尝试在屏幕上禁用渲染,但这没有影响.因此,GC来自游戏代码.

  • 在Safari中进行测量显示的结果与Chrome的性能"标签相似.

解决方案

我想我找到了一种解决方法:我删除了引擎中的循环,并在按下某个键时使每个帧都运行.

这样,我可以拍摄堆快照,仅处理一帧,然后快速拍摄另一个快照(在GC启动之前).在快照之间分配对象".视图似乎更加一致,并且显示了JS引擎的内部数据(如函数作用域)占用的大量内存.

I'm building a game using JavaScript that runs at 60 FPS and have noticed a large amount of garbage collection happening (7.2 MB every 1.5 seconds, see below Chrome DevTools), which has a noticeable impact on frame rate.

I've used the Allocation Timeline to see what is being added to memory every frame. As you can see below, there is 4.1 kB allocated every frame. So I would expect to see 369 kB garbage collected every 1.5 seconds.

Why is there an order of magnitude difference between the two? I've been using the Allocation Timeline to reduce the memory used (it was originally 18 kB every frame). However this has had almost zero impact when looking at the Performance tab.

Is there are any way to know what is being garbage collected, as the Allocation Timeline doesn't seem to be correct?

Additional Info

  • Here's a Heap Snapshot comparison between two moments in the game. This also doesn't seem consistent, and it includes lots of things which I would not expect to have changed every frame.

  • I tried removing the amount of objects (in an array) in my game and this did make a big impact in the Performance tab. But I really want to see this array listed somewhere in the DevTools so I can work on optimising it.

  • I tried disabling rendering on the screen, but this didn't have an impact. So the GC is from game code.

  • Measuring in Safari shows similar results to Chrome's performance tab.

解决方案

I think I found a way around this: I removed the loop in the engine and have each frame run when a key is pressed.

This way I can take a heap snapshot, progress just one frame, then quickly take another snapshot (before GC kicks in). The "Objects allocated between snapshot" view seems to be more consistent, and shows a lot of memory used up by the JS engine's internal data like function scope.

这篇关于Chrome DevTools内存不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆