Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Analyze V8 HeapSnapShot By Rust

License

NotificationsYou must be signed in to change notification settings

zhangyuang/v8-profiler-rs

Repository files navigation

English |简体中文

Introduction

v8-profiler-rs is a project developed inRust for intelligent online analysis ofV8 heapsnapshot files. It helps developers using V8-based applications likeNode.js/Chrome/Deno/Electron to better understand program memory structure and assist in locating memory leaks.

How to start

Recommend usingOnline Demo, it's more convenient. Or you can start it in local.

$ git clone https://github.com/zhangyuang/v8-profiler-rs.git$cd v8-profiler-rs/example$ yarn&& yarn start

Online Demo

We have deployed anonline website where you can upload and analyze V8 memory snapshots in real-time. We recommend usingSafari orFirefox browsers, aswasm execution performance is significantly better than inChrome .

image

Default example

View default example by clicking theExample button on the top left corner.

The code of default example is as follows:

constexpress=require('express');constapp=express();constfs=require('fs')// the memory leak codelettheThing=null;letreplaceThing=function(){letleak=theThing;letunused=function(){if(leak)console.log("hi")};theThing={bigNumber:1,bigArr:[],longStr:newArray(1000000),someMethod:function(){console.log('a');}};};letindex=0app.get('/leak',functionclosureLeak(req,res,next){replaceThing();index++if(index===1){conststream=require('v8').getHeapSnapshot()stream.pipe(fs.createWriteStream('small-closure.heapsnapshot'))}if(index===40){conststream=require('v8').getHeapSnapshot()stream.pipe(fs.createWriteStream('medium-closure.heapsnapshot'))}if(index===50){conststream=require('v8').getHeapSnapshot()stream.pipe(fs.createWriteStream('big-closure.heapsnapshot'))}res.send('Hello Node');});app.listen(3001);

Analyze Report

There are two types of reports: single report and compare report.

Single Report

Analyze Report with singleOnly show nodes with more than 20 occurrencesMemory retained by constructor typeclosure:156409.05 MBObject:156408.32 MBsystem / Context:154881.33 MBarray:4579.70 MBsynthetic:1533.60 MBArray:1526.16 MBWeakMap:1526.01 MB(compiled code):2.96 MBstring:2.10 MBThere are some nodes that are duplicated too many timessomeMethod @70761:202(memoryleak - demo / closure / index.js)HttpError @95957:44(node_modules / http - errors / index.js)parse @89241:33(node_modules / ms / index.js)ClientError @50469:31(node_modules / http - errors / index.js)indexOf @49211:27(node_modules / object - inspect / index.js)send @126827:23(node_modules / send / index.js)resolve @98543:23(node_modules / express / lib / view.js)

Compare Report

Analyze Report with compareOnly show nodes with more than 20 occurrencesAdditional nodes by constructor type(compiled code):242ArrayBuffer:127system / JSArrayBufferData:127Buffer:126Node / std::basic_string:78closure:69Array:46array:44system / Context:34Object:29Bigger nodes by constructor type(compiled code):48closure:25Bigger nodes by increased size@1: +83.54 MBObject @6613:+76.30 MBArray @154471:+76.30 MBArray @154499:+76.30 MBapp @6603:+76.30 MB(node_modules / .pnpm / express @4 .18 .2 / node_modules / express / lib / express.js)router @6533:+76.30 MB(node_modules / .pnpm / express @4 .18 .2 / node_modules / express / lib / router / index.js)closureLeak @6481:+76.30 MB(memoryleak - demo / closure / index.js)Route @6511:+76.30 MBLayer @6517:+76.30 MBLayer @6497:+76.30 MBServer @6609:+76.30 MBsystem / Context @6483:+76.30 MB

Implemented Features

🚀 indicates implemented features. This application is continuously being updated, and updates will be synchronized to the README.md. Please stay tuned. If this application helps you, please give it a Star ✨

MilestoneStatus
Parse V8 snapshot to generate complete node information🚀
View node source location and constructor🚀
Generate analysis reports🚀
Frontend visualization support🚀
Filter nodes by ID and name🚀
Filter number of nodes and view detailed node references🚀
Filter reference depth and number of references🚀
Compare two snapshot files🚀
Support two comparison types: new nodes/increased GC size🚀
Automatically filter non-business nodes based on node count🚀
Support uploading local serialized JSON files🚀
ImplementWasm + WebWorker parsing to avoid site unresponsiveness🚀
Optimize parsing performance and reduce memory usage🚀

Why Rust

Parsing V8 memory snapshots involves a lot of computational operations. CPU-intensive scenarios are inherently not JavaScript's strong suit.

After reading Chrome's official memory analysis tool source code, I found it uses many tricks to ensure performance, making the code highly complex and difficult to maintain.

Rust is perfect for this scenario, providing excellent performance while maintaining code readability. Rust's superior multi-threading capabilities are exactly what we need, as parsing computation logic is ideal for multi-threaded optimization. We will continue optimizing computational performance in future versions.

This application's approach can be applied to any programming language with GC. We will strive to support memory analysis for more programming languages in the future.

Finally, Rust's official WebAssembly support is excellent, allowing us to easily compile Rust code to WebAssembly for browser use.

Handling Parse Timeout Issues

For very large files, you may encounter Wasm memory overflow or long parse times. If this occurs, try usingSafari orFirefox browsers.

Contact

The prohect has been updating, if you have any questions or suggestions, please submit anissue

How to sponsor me

There are two ways to sponsor me both Alipay and WeChat

Eth address: 0x87a2575a5d4dbD5f965e3e3a3d20641BC9a5d192

How to use

Open theonline demo and upload theheapsnapshot file. You can upload one or two files for comparison.

There will render heapsnapshot nodes in web page.

The node fields are as follows:

{"node_type":string;// node type"name":string;// node name"id":number;// node id"size":number;// node self size"edge_count":number;// node edge count"retained_size":number;// node retained size, the free size of the node after GC"pt":number;// the ratio of self size / retained size"edges":{"edge_type":string;// edge type"to_node":number;// the id of the node that the edge points to"name_or_index":string;// the name or index(for array) of the edge}[];"source":string;// the source file of the node"constructor":string;// the constructor of the node"percent":string;// the retained size ratio of the node}

About

Analyze V8 HeapSnapShot By Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp