I'm writing a client-heavy site. Since my own testing will only get me so far, I'd like to gather some statistics on how it's performing in the wild.
I'm imagining adding some sort of profiling code to my app which will run some percentage of the time (so it doesn't slow everyone down) and sending that info home.
Adding some timing benchmarks should be easy, but what really becomes a problem with long-running pages with lots of JS is memory usage. Is there a way to instrument the memory used by my app from normal, unprivileged JS code in any of the major browsers? Are there any other good profiling metrics that are available?
Some high-level languages, such as JavaScript, utilize a form of automatic memory management known as garbage collection (GC). The purpose of a garbage collector is to monitor memory allocation and determine when a block of allocated memory is no longer needed and reclaim it.
JavaScript code can experience memory leaks by keeping hidden references to objects. Hidden references can cause memory leaks in many unexpected ways.
“Variables in JavaScript (and most other programming languages) are stored in two places: stack and heap. A stack is usually a continuous region of memory allocating local context for each executing function. Heap is a much larger region storing everything allocated dynamically.
In Chrome:
for (var key in performance.memory) {
alert(key+': '+performance.memory[key]);
}
DEMO: http://jsfiddle.net/usuXV/1/
Sample output:
jsHeapSizeLimit: 1620000000
usedJSHeapSize: 10000000
totalJSHeapSize: 16100000
You can also use console.memory
. Seems to return the same results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With