Well-deployed technologies

To guarantee a smooth experience no matter what and take advantage of available processing power, games typically split the work across multiple threads. Web Workers allow to run JavaScript code in the background. This is particularly useful to keep the user interface responsive by offloading the most resource-intensive operations into a background process.

Note: Due to Spectre, support for the SharedArrayBuffer object, which allows to share memory between threads, has been temporarily removed from most Web browsers. As such communications between workers is mostly limited to message passing for the time being.

The Web Performance Working Group developed a number of specifications that expose timing hooks to Web applications, to analyze time spent doing various tasks. The High-Resolution Time exposes a monotonic sub-millisecond resolution clock to Web applications so that they can precisely measure time elapsed between two events. The Performance Timeline defines a unified interface to store and retrieve performance metric data. Individual performance metric interfaces are defined in separate specifications:

  • Navigation Timing exposes timing information related to navigation and elements;
  • Resource Timing exposes timing information for resources in a document;
  • User Timing help applications measure the performance of their applications using high precision timestamps.

The Cooperative Scheduling of Background Tasks specification defines the requestIdleCallback method that allows scheduling an operation at the next opportunity when the app is not processing another operation.

The Timing control for script-based animations API can help reduce the usage of resources needed for playing animations.

FeatureSpecification / GroupMaturityCurrent implementations
Select browsers…
MultithreadingWeb workers in HTML Standard
WHATWG
Living Standard
Timing hooksHigh Resolution Time Level 2
Web Performance Working Group
Recommendation
Performance Timeline
Web Performance Working Group
Candidate Recommendation
Navigation Timing Level 2
Web Performance Working Group
Working Draft
Resource Timing Level 2
Web Performance Working Group
Candidate Recommendation
User Timing Level 2
Web Performance Working Group
Recommendation
Priority handlingCooperative Scheduling of Background Tasks
Web Performance Working Group
Working Draft
Animation optimizationrequestAnimationFrame in HTML Standard
WHATWG
Living Standard

Technologies in progress

Games that require tight memory and processing controls are typically written in C++ (or equivalent). WebAssembly (Wasm) is a low-level bytecode format that runs with near-native speed in web browsers and supports compilation from C, C++, and other languages. Most 3D game engines now support WebAssembly as a compilation target. Wasm makes it possible to reuse the same efficient codebase across platforms.

The Resource Hints and Preload specifications let developers optimize the download of resources by enabling to delay either the download or the execution of the downloaded resource.

The Service Workers specification defines a mechanism that allows applications to intercept outgoing network requests and respond to them directly. Applications can take advantage of this mechanism to implement a flexible cache logic directly and thus avoid lengthy requests to the server.

Server Timing enables a server to communicate performance metrics about the request-response cycle to the user agent, and allows applications to act on these metrics to optimize application delivery.

The Long Tasks API exposes a mechanism to detect long running tasks that monopolize the user interface's main thread for extended periods of time.

The Paint Timing specification allows the application to capture a series of key moments such as first paint and first contentful paint during page load.

To ensure optimal performance when animating parts of an app, developers can make use of the CSS will-change property to let browsers compute the animation ahead of its occurrence.

The CSS contain property can indicate that the element’s subtree is independent of the rest of the page. This also enables heavy optimizations by user agents when used well, in particular to skip over content that is off-screen knowing that it won't affect the rendering of the content that is on-screen.

The Identifiers for WebRTC's Statistics API defines a set of Web IDL objects that allow access to the statistical information about a RTCPeerConnection, allowing web apps to monitor the performance of the underlying network and media pipeline.

FeatureSpecification / GroupMaturityCurrent implementations
Select browsers…
Low-level bytecode formatWebAssembly Core Specification
WebAssembly Working Group
Recommendation
Network prioritizationResource Hints
Web Performance Working Group
Retired
Preload
Web Performance Working Group
Retired
CachingService Workers 1
Service Workers Working Group
Candidate Recommendation
Timing hooksServer Timing
Web Performance Working Group
Working Draft
Long Tasks API 1
Web Performance Working Group
Working Draft
Paint Timing 1
Web Performance Working Group
Working Draft
Rendering performanceCSS Will Change Module Level 1
CSS Working Group
Candidate Recommendation
CSS Containment Module Level 1
CSS Working Group
Recommendation
Real-time communicationsIdentifiers for WebRTC's Statistics API
WebRTC Working Group
Candidate Recommendation

Exploratory work

On top of for rendering, some games may also wish to take advantage of the GPU to run heavy computations. To some extent, this is already doable through WebGL. The GPU for the Web Community Group is designing a new Web API to expose modern 3D graphics (first) and computation capabilities (afterwards) in a performant, powerful and safe manner, with a view to being agnostic of and compatible with existing native system platforms such as Direct3D, Metal, or Vulkan.

Coordination between threads may require the use of locks. The Web Locks API proposal describes a mechanism that allows scripts to asynchronously acquire a lock over a resource, hold it while work is performed, then release it.

The work on the Frame Timing API aims at providing detailed information on the frame-per-second obtained when an application is running on the user device.

The work on the Event Timing Web Perf API exposes a mechanism to measure the latency of some events triggered by user interaction.

The Priority Hints specification lets developers signal the priority of each resource they need to download, complementing existing browser loading primitives such as preload.

The CSS Animation Worklet API provides a method to create scripted animations that control a set of animation effects. The API is designed to make it possible for user agents to run such animations in their own dedicated thread to provide a degree of performance isolation from main thread.

User agents may implement default rules for scrolling such as scroll chaining and overscroll affordances that web applications may wish to disable to enhance pull-to-refresh and infinite scrolling interaction paradigms, which are common on mobile devices. This can be achieved through scripting, but negatively affects scrolling performances as the application needs to listen to touch events without setting the passive flag to override the default behavior when needed. The CSS overscroll-behavior property introduces control over the behavior of a scroll container when its scrollport reaches the boundary of its scroll box, allowing web applications to disable default rules for scrolling efficiently.

FeatureSpecification / GroupImplementation intents
Select browsers…
GPU computationWebGL Specification
Khronos Group
MultithreadingWeb Locks API
W3C
Timing hooksFrame Timing
Web Performance Working Group
Event Timing API
W3C
Network prioritizationPriority Hints
Web Platform Incubator Community Group
Animation optimizationCSS Animation Worklet API
CSS Working Group
Scrolling optimizationCSS Overscroll Behavior Module Level 1
CSS Working Group

Features not covered by ongoing work

Artificial Intelligence (AI)
Many games implement a so-called game AI to generate intelligent behaviors for game characters that are not under the control of a real player. While the concept of AI in games is different from the notion of AI in other fields, a game AI may reuse similar techniques, e.g. based on machine learning, neural networks and other data mining algorithms. A sub-ideal solution to implement such algorithms in Web browsers is to use WebAssembly and WebGL. An early proposal for a Base Machine Learning API was made in October 2017 to expose more suitable primitives to Web applications, but has not yet led to standardization work in that field at W3C.