Version: 2021.3
Interaction with browser scripting
对 WebGL 构建进行调试和故障排除

WebGL performance considerations

In general, the WebGL performance is close to native apps on the GPU, because the WebGL graphics API uses your GPU for hardware-accelerated rendering. The only exception is the slight overhead for translating WebGL API calls and shaders to your OS graphics API (typically DirectX on Windows, OpenGL on Mac, and Linux).

On the CPU, Emscripten translates your code into WebAssembly, the performance of which depends on the web browser you’re using. For more information, see the Unity blog post WebAssembly Load Times and Performance.

Following are the additional considerations that you must be aware of: * The JavaScript language does not support multi-threading or SIMD. * Any code that benefits from these features are likely to be slower than other code. * You cannot write threading or SIMD code in WebGL in your scripts, but as some engine parts are multi-threaded or SIMD optimized, they offer low performance on WebGL. For example, WebGL Skinning is both multi-threaded and SIMD-optimized.

Tip: To see how Unity distributes work to different threads on non-WebGL platforms, see the new timeline Profiler in Unity.

WebGL-specific settings which affect performance

For best performance, set the optimization level to Faster in the Build Player window, and set Exception support to None in the Player settings for WebGL by expanding Other Settings > Stack Trace.

Profiling WebGL

WebGL supports the Unity profiler. See the Profiler documentation to learn how to set it up.

WebGL content in background tabs

如果在 WebGL 平台的 Player 设置中启用了 Run in background,或者如果启用了 Application.runInBackground,您的内容将在画布或浏览器窗口失去焦点时继续运行。

但是,某些浏览器可能会限制在后台标签页中运行的内容。如果包含该内容的标签页不可见,在大多数浏览器中,您的内容每秒才会更新一次。请注意,这将导致 Time.time 比平常采用默认设置时更慢,因为 Time.maximumDeltaTime 的默认值小于一秒。

限制 WebGL 性能

You might want to run your WebGL content at a lower frame rate in some situations to reduce CPU usage. For example, on other platforms, you can use the Application.targetFrameRate API to do so.

When you don’t want to throttle performance, set this API to the default value of –1, rather than to a high value. This allows the browser to adjust the frame rate for the smoothest animation in the browser’s render loop, and might produce better results than Unity trying to do its own main loop timing to match a target frame rate.


  • 2019–06–10 页面已修订
Interaction with browser scripting
对 WebGL 构建进行调试和故障排除
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961