JavaScript性能预热 [英] JavaScript performance warmup

查看:77
本文介绍了JavaScript性能预热的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个WebGL游戏,使用一段时间后,它的速度确实要快得多.每次我第一次运行它时,速度都很慢而且结结巴巴.先运行几秒钟占用大量CPU的代码,这样浏览器才能准备好使用它的全部功能吗?

I'm creating a WebGL game and it's really much faster after some time using it. Every time I run it for the first time it's slow and stutters. Would running some CPU intensive code for few seconds first prepare browser to use it's full power?

我已经在一个工作人员中运行ammo.js,这可以极大地提高工作效率,但是开始播放的前几分钟仍然慢得多.这可能是我管理电源的笔记本电脑策略吗?

I'm already running ammo.js in a worker which gives an enormous boost, but first few minutes of playing are still much slower. Could this be my laptop strategy to manage power?

推荐答案

我可以想到四件事:

  1. 浏览器使用一种称为JIT(即时编译)的技术来加快代码最常用部分的执行速度.但是,要检测哪个部分最常用,浏览器会花一些时间.

  1. The browsers use a technique called JIT (Just In Time compilation) to accelerate the speed of execution for the most-used parts of your code. However, to detect which part is most used, browsers give it some time.

笔记本电脑通常以较低的速度运行CPU,以节省电池电量.但是,当CPU使用率过高时(例如在玩游戏时),它们会提高频率以从处理器中获取更多汁.例如,英特尔Speedstep http://en.wikipedia.org/wiki/SpeedStep

Laptops usually run the CPU at a lower speed to preserve battery. However, when the CPU usage is too high (like when you're playing a game), they step up the frequency to get more juice from the processor. For example Intel Speedstep http://en.wikipedia.org/wiki/SpeedStep

某些笔记本电脑有两个图形卡(例如,许多Macbook Pro).一种是默认的Intel一种,它们用于渲染普通的GUI窗口,另一种用于图形密集型应用程序.功能更强大的图形卡通常默认情况下处于关闭状态,并且仅在需要时使用(因为它会消耗更多电池,并且系统热量还会上升,并且系统会产生噪音).尽管系统不太可能在运行3D应用程序的过程中更换图形卡.

Some laptops have two graphic cards (many Macbook Pros for example). One is the default Intel one that they use for rendering normal GUI windows and the other that is used for graphically intensive applications. The more powerful graphic card is usually turned off by default and only used when needed (because it consumes more battery and also system heat will go up and system will be noisy). Though it's unlikely that the system will change graphic cards in the middle of running a 3D application.

这些都是您无法控制的.游戏引擎通常将查找表用于频繁计算的值,以加快其运行时间.游戏引擎可能会按需填充查找表.

These are all out of your control. The game engines usually use lookup tables for frequently computed values in order to accelerate their run time. It might be possible that your game engine fills the lookup table on demand.

尽管如此,所有这些项目都不应该花费几分钟"来加快速度.通常只需要几秒钟.所以它仍然很腥.

Nevertheless none of these items should take "a couple of minutes" to get up to speed. Usually it takes just a few seconds. So it's still fishy.

这篇关于JavaScript性能预热的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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