All Projects → justjavac → V8 Javascript Memory

justjavac / V8 Javascript Memory

V8 JavaScript 内存占用分析

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to V8 Javascript Memory

Lighthouse
Automated auditing, performance metrics, and best practices for the web.
Stars: ✭ 23,903 (+51863.04%)
Mutual labels:  chrome-devtools
Liquidcore
Node.js virtual machine for Android and iOS
Stars: ✭ 765 (+1563.04%)
Mutual labels:  v8
Rust V8worker2
Minimal Rust binding to V8 (based on ry/libv8worker2)
Stars: ✭ 33 (-28.26%)
Mutual labels:  v8
Devtools Docs
The legacy documentation for Chrome DevTools.
Stars: ✭ 622 (+1252.17%)
Mutual labels:  chrome-devtools
Debugger Protocol Viewer
DevTools Protocol API docs—its domains, methods, and events
Stars: ✭ 749 (+1528.26%)
Mutual labels:  chrome-devtools
Cef4delphi
CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
Stars: ✭ 785 (+1606.52%)
Mutual labels:  v8
React Native V8
Opt-in V8 runtime for React Native Android
Stars: ✭ 514 (+1017.39%)
Mutual labels:  v8
Bytenode
A minimalist bytecode compiler for Node.js
Stars: ✭ 1,012 (+2100%)
Mutual labels:  v8
Js Leakage Patterns
🎯这是关于JavaScript内存泄露和CSS优化相关序列文章,相信你读完会有所收获的✈️
Stars: ✭ 756 (+1543.48%)
Mutual labels:  chrome-devtools
V8 Cffi
Embed the V8 Javascript Interpreter into Python
Stars: ✭ 31 (-32.61%)
Mutual labels:  v8
Storyboard
End-to-end, hierarchical, real-time, colorful logs and stories
Stars: ✭ 652 (+1317.39%)
Mutual labels:  chrome-devtools
Chromedp
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.
Stars: ✭ 7,057 (+15241.3%)
Mutual labels:  chrome-devtools
V8 Bailout Reasons
🔧 A list of Crankshaft bailout reasons with examples
Stars: ✭ 861 (+1771.74%)
Mutual labels:  v8
V8.dev
The source code of v8.dev, the official website of the V8 project.
Stars: ✭ 567 (+1132.61%)
Mutual labels:  v8
Cljs Devtools
A collection of Chrome DevTools enhancements for ClojureScript developers
Stars: ✭ 969 (+2006.52%)
Mutual labels:  chrome-devtools
Type Profile
Collect runtime type information 😻 of your JavaScript code.
Stars: ✭ 518 (+1026.09%)
Mutual labels:  v8
Dejavue
Visualization and debugging tool built for Vue.js
Stars: ✭ 785 (+1606.52%)
Mutual labels:  chrome-devtools
V8 Source Read
V8 探秘
Stars: ✭ 43 (-6.52%)
Mutual labels:  v8
Ec Devtools
ec-devtools是支持canvas库 ( easycanvas , https://github.com/chenzhuo1992/easycanvas ) 的chrome调试工具,能对canvas的元素的样式、物理属性等进行修改,达到所见即所得的效果,提高调试效率
Stars: ✭ 35 (-23.91%)
Mutual labels:  chrome-devtools
Monomorphist
monomorphist - a JavaScript performance companion
Stars: ✭ 30 (-34.78%)
Mutual labels:  v8

v8-javascript-memory

V8 JavaScript 内存占用分析。

回答知乎的问题:v8 中 Symbol() 、Object.create(null) 和 {} 的内存占用分别是多少?

步骤

  1. 使用 Chrome 浏览器访问 https://justjavac.com/v8-javascript-memory/

  2. 打开 Dev Tools,如图:

  1. 选择 Memory 标签页
  2. 点击 take heap snapshots
  3. 在过滤框中输入 ho 快速过滤出 holder

名次解释

Shallow Size:对象自身占用内存的大小,不包括它引用的对象。JavaScript 对象会将一些内存用于自身的说明和保存中间值。通常,只有数组和字符串会有明显的浅层大小。

Retained Size:这是将对象本身连同其无法从 GC root 到达的相关对象一起删除后释放的内存大小。

单位是字节(Byte)。

分析

从截图中可以看到,Symbol() 的内存占用是 16。

Object.create(null) 自身占用 12,总占用 88。

{} 自身占用 28,总占用 28。

继续展开你会看到其他信息:

  1. __proto__ 是原型链。
  2. map 就是很多文章都在介绍的 V8 对象的黑魔法 Hidden Class。

使用 V8 进行调试

V8 的 %DebugPrint() 函数可以打印出对象的调试信息。这需要手动使用 --is_debug=true 参数来编译 V8。

代码:

let o = {};
%DebugPrint(o);

运行:d8 --allow_natives_syntax heap.js

输出:

DebugPrint: 0x2604080c60e9: [JS_OBJECT_TYPE]
 - map: 0x2604082802d9 <Map(HOLEY_ELEMENTS)> [FastProperties]
 - prototype: 0x2604082413c9 <Object map = 0x2604082801c1>
 - elements: 0x2604080406e9 <FixedArray[0]> [HOLEY_ELEMENTS]
 - properties: 0x2604080406e9 <FixedArray[0]> {}
0x2604082802d9: [Map]
 - type: JS_OBJECT_TYPE
 - instance size: 28
 - inobject properties: 4
 - elements kind: HOLEY_ELEMENTS
 - unused property fields: 4
 - enum length: invalid
 - back pointer: 0x26040804030d <undefined>
 - prototype_validity cell: 0x2604081c0451 <Cell value= 1>
 - instance descriptors (own) #0: 0x2604080401b5 <DescriptorArray[0]>
 - prototype: 0x2604082413c9 <Object map = 0x2604082801c1>
 - constructor: 0x2604082413e5 <JSFunction Object (sfi = 0x2604081c5869)>
 - dependent code: 0x2604080401ed <Other heap object (WEAK_FIXED_ARRAY_TYPE)>
 - construction counter: 0

注: 虽然 node 和 deno 都支持 V8 的 --allow_natives_syntax 参数,但是如果你使用 node 或者 deno 运行,只能得到一行类似 0x053bedbc1399 <Object map = 0x53b630d1d51> 的输出。 如果想得到详细的输出,必须手动编译,并且在编译过程中增加 --is_debug=true 参数。

License

本作品由 justjavac 创作,采用知识共享署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议进行许可。凡是转载的文章,翻译的文章,或者由其他作者投稿的文章,版权归原作者所有。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].