Perform a health check for your JavaScript Memory Performance

Source: Internet
Author: User

Reprinted please indicate Source: http://blog.csdn.net/horkychen

Because of the language features of JavaScript, its memory management is mainly handled by the javascript interpreter of the browser, which is widely known as the garbage collection mechanism. However, the inherent limit also requires the memory used by JS to be controlled. In particular, HTML5 games require more and more JS memory management.

Currently, many materials focus on the execution performance of JavaScript. Tools such as firebug can provide relevant functions. The following are some reference pages:

Javascript Performance Analysis-tool (Yui Profiler)

Jsprofiler-js Performance Analysis Tool

Mobile web application development high-performance JavaScript Article (3) JavaScript loading parsing and deployment


Use of JavaScript Memory Leak tools (Memory leakage and memory consumption are not a topic, but they can also be used as a reference)

Currently, only chrome development tools are available to obtain the heap status occupied by the current script. In profiles, select heap snapshot analysis.

(It shows that an object occupies more than 17 MB of memory)

For details, clickHere.

 

For other browsers, you can use vmmap to view the overall memory status of the browser:

The following is the result obtained by vmmap on safari in Mac OS (the execution is vmmapPID. This PID is another process called by safari.):

Region type virtual
============================
...

Js jit generated code 256.0 m
Js jit generated code (Reserved) 768.0 M reserved VM address space (unallocated)
Js vm Register File 4096 K
JS Garbage Collector 34.6 m
Malloc 625.0 m See malloc zone table below
...

Note: If the number behind JS garbage collector is relatively large, there may be a large number of closures in the script, making GC ineffective in a timely manner.

 

Use the heap command to view the status in the malloc zone:

Virtual allocation bytes
Malloc zone size count allocated % full
========================================================== =
Javascriptcore fastmalloc_0x7fff7d8b8148 534.1 M 2863601 307.6 M 57%
Defaultmalloczone_0x10b033000 41.1 M 42615 K 9643

......

I think you have seen some problems, and the memory overhead has gone above MB!

The next step is to analyze what is consuming our memory to optimize script execution.

Good luck!

 

* Vmmap is also available in windows. It comes from the well-known sysinternals component. Please refer to [msdn link] Here.

* The heap view in Windows is here.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.