Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome usedJSHeapSize property

First of all, I've looked around the internet and found it quite badly documented. Somewhere in my code I have a big memory leak that I'm trying to track and after using:

window.performance.memory.usedJSHeapSize 

it looks like the value remains at the same level of 10MB, which is not true because when we compare to the values either visible here:

chrome://memory-internals/

or if we look at the Timeline in devTools we can see a big difference. Does anyone encountered a similar issue? Do I need to manually update these values (to run a command "update", "measure" etc?)

Following this topic: Information heap size it looks like this value is increased by a certain step, can we somehow see what is it or modify it? In my case from what I can see now the page has about 10MB, 30 minutes later there will be about 400MB, and half an hour after the page will crash.. Any ideas guys?

(Why the code is leaking it's a different issue, please treat this one as I was trying to use this variable to create some kind of test).

like image 756
Pete Kozak Avatar asked Aug 06 '14 17:08

Pete Kozak


People also ask

What is jsheapsizelimit in JavaScript?

There are three pieces of information in the memory object: jsHeapSizeLimit – the maximum amount of heap size that your JS engine can ask from the operating system. totalJSHeapSize – the actual memory allocated by the JS engine from the operating system.

How to use chrome scripting API?

In order to use the chrome.scripting API, you need to specify a "manifest_version" of 3 or higher and include the "scripting" permission in your manifest file. ... You can use the chrome.scripting API to inject JavaScript and CSS into websites.

Why are the values quantized in chrome's cache?

The values are quantized as to not expose private information to attackers. If Chrome is run with the flag --enable-precise-memory-info the values are not quantized.

How to inject JavaScript and CSS into Chrome extensions?

This is similar to what you can do with content scripts, but by using the chrome.scripting API, extensions can make decisions at runtime. You can use the target parameter to specify a target to inject JavaScript or CSS into.


1 Answers

There's a section of the WebPlatform.org docs that explains this:

The values are quantized as to not expose private information to attackers. If Chrome is run with the flag --enable-precise-memory-info the values are not quantized.

http://docs.webplatform.org/wiki/apis/timing/properties/memory

So, by default, the number is not precise, and it only updates every 20 minutes! This should explain why your number doesn't change. If you use the flag, the number will be precise and current.

The WebKit commit message explains:

This patch adds an option to expose quantized and rate-limited memory
information to web pages. Web pages can only learn new data every 20
minutes, which helps mitigate attacks where the attacker compares two
readings to extract side-channel information. The patch also only
reports 100 distinct memory values, which (combined with the rate
limits) makes it difficult for attackers to learn about small changes in
memory use.

like image 113
Matthias Avatar answered Oct 06 '22 01:10

Matthias