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:
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.
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 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.
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.
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.