Friday, November 22, 2024

Google Chrome reduced cookie requests to improve performance

Must read

Google shared details on a recently introduced Chrome feature that changes how cookies are requested, with early tests showing increased performance across all platforms.

In the past, single-process browsers managed cookies easily because the data was kept in memory. However, modern browsers like Chrome use multiple processes to improve performance and security.

Chrome runs a new process for every window and several other features. This means the method that handles cookies has to deal with more queries, which can slow things down.

Google found that repeated requests for cookies caused many slow interactions in Chrome.

“We discovered through field traces of slow interactions that some websites were triggering inefficient scenarios with cookies being fetched multiple times in a row,” Google noted in a blog post.

“We landed additional metrics to measure how often a GetCookieString() IPC was redundant (same value returned as last time) across all navigations.”

“We were astonished to discover that 87% of cookie accesses were redundant and that, in some cases, this could happen hundreds of times per second.”

In some cases, especially when multiple sites made rapid requests simultaneously, these requests happened hundreds of times per second, causing significant delays. Ultimately, the old way of fetching cookies synchronously (one at a time) from the network service was causing a bottleneck.

To fix this, Google introduced a new system called Shared Memory Versioning, which was enabled by default in March.

Instead of constantly checking with the network service, Chrome now keeps a local copy of the cookie data and its version number.

This allows Chrome to check if a cookie has the latest data without making repeated requests.

Chromium change reduces cookie requests
Chromium change reduces cookie requests
Source: Google

According to Google engineers, this change has reduced the number of cookie-related messages by 80% and sped up cookie access by 60%.

“The idea is that each value of document.cookie is now paired with a monotonically increasing version. Each renderer caches its last read of document.cookie alongside that version,” Google explained how the feature works.

“The network service hosts the version of each document.cookie in shared memory. Renderers can thus tell whether they have the latest version without having to send an inter-process query to the network service,” the company added.

In early tests, Google observed that the update improves performance by up to 5% across all platforms.

As a result, more websites are passing Core Web Vitals, which refers to a set of metrics for measuring page loading performance, interactivity, and visual stability on real devices.

Latest article