Version: 2022.3
Language : English
Debug and troubleshoot WebGL builds
WebGL Networking

WebGL performance considerations

In general, the WebGLA JavaScript API that renders 2D and 3D graphics in a web browser. The Unity WebGL build option allows Unity to publish content as JavaScript programs which use HTML5 technologies and the WebGL rendering API to run Unity content in a web browser. More info
See in Glossary
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 shadersA program that runs on the GPU. More info
See in Glossary
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 scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
    See in Glossary
    , but as some engine parts are multi-threaded or SIMD optimized, they offer low performance on WebGL. For example, WebGL SkinningThe process of binding bone joints to the vertices of a character’s mesh or ‘skin’. Performed with an external tool, such as Blender or Autodesk Maya. More info
    See in Glossary
    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 ProfilerA window that helps you to optimize your game. It shows how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating, or in your game logic. More info
See in Glossary
in Unity.

WebGL-specific settings which affect performance

To improve performance, 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

If Run in background is enabled in the Player settings for the WebGL platform, or if you enable Application.runInBackground, your content continues to run when the canvas or the browser window loses focus.

However, some browsers can throttle content running in background tabs. If the tab with your content isn’t visible, your content only updates once per second in most browsers. Note that this causes Time.time to progress slower than usual with the default settings, as the default value of Time.maximumDeltaTime is lower than one second.

Throttling WebGL performance

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.

Debug and troubleshoot WebGL builds
WebGL Networking
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961