{"id":15407892,"url":"https://github.com/zhangyuang/v8-profiler-rs","last_synced_at":"2025-04-04T21:07:32.917Z","repository":{"id":50440109,"uuid":"448874257","full_name":"zhangyuang/v8-profiler-rs","owner":"zhangyuang","description":"Analyze V8 HeapSnapShot By Rust","archived":false,"fork":false,"pushed_at":"2025-03-09T07:57:43.000Z","size":37393,"stargazers_count":198,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-28T20:06:54.569Z","etag":null,"topics":["heapsnapshot","rust","v8"],"latest_commit_sha":null,"homepage":"https://v8.ssr-fc.com/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhangyuang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-17T11:55:18.000Z","updated_at":"2025-03-27T00:06:13.000Z","dependencies_parsed_at":"2024-10-19T12:39:05.139Z","dependency_job_id":"27a9e888-d058-4cad-a145-b4b262cdddb0","html_url":"https://github.com/zhangyuang/v8-profiler-rs","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"93631c9272d203f9d25eed2198890314252bf39e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"napi-rs/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyuang%2Fv8-profiler-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyuang%2Fv8-profiler-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyuang%2Fv8-profiler-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyuang%2Fv8-profiler-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangyuang","download_url":"https://codeload.github.com/zhangyuang/v8-profiler-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249524,"owners_count":20908212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heapsnapshot","rust","v8"],"created_at":"2024-10-01T16:30:03.954Z","updated_at":"2025-04-04T21:07:32.900Z","avatar_url":"https://github.com/zhangyuang.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English](./README.md) | [简体中文](./README_Zh.md)\n\n# Introduction\n\n[v8-profiler-rs](https://github.com/zhangyuang/v8-profiler-rs) is a project developed in `Rust` for intelligent online analysis of `V8 heapsnapshot` files. It helps developers using V8-based applications like `Node.js/Chrome/Deno/Electron` to better understand program memory structure and assist in locating memory leaks.\n\n## How to start\n\nRecommend using [Online Demo](https://v8.ssr-fc.com/), it's more convenient. Or you can start it in local.\n\n```bash\n$ git clone https://github.com/zhangyuang/v8-profiler-rs.git\n$ cd v8-profiler-rs/example\n$ yarn \u0026\u0026 yarn start\n```\n\n## Online Demo\n\nWe have deployed an [online website](https://v8.ssr-fc.com/) where you can upload and analyze V8 memory snapshots in real-time. We recommend using `Safari` or `Firefox` browsers, as `wasm` execution performance is significantly better than in `Chrome` .\n\n![image](https://res.wx.qq.com/shop/public/2025-02-12/e56b4e3d-a8d1-4638-b7b7-f92412e54a8f.png)\n\n## Default example\n\nView default example by clicking the `Example` button on the top left corner.\n\nThe code of default example is as follows:\n\n```js\nconst express = require('express');\nconst app = express();\nconst fs = require('fs')\n// the memory leak code\nlet theThing = null;\nlet replaceThing = function() {\n    let leak = theThing;\n    let unused = function() {\n        if (leak)\n            console.log(\"hi\")\n    };\n\n    theThing = {\n        bigNumber: 1,\n        bigArr: [],\n        longStr: new Array(1000000),\n        someMethod: function() {\n            console.log('a');\n        }\n    };\n};\nlet index = 0\napp.get('/leak', function closureLeak(req, res, next) {\n    replaceThing();\n    index++\n    if (index === 1) {\n        const stream = require('v8').getHeapSnapshot()\n        stream.pipe(fs.createWriteStream('small-closure.heapsnapshot'))\n    }\n    if (index === 40) {\n        const stream = require('v8').getHeapSnapshot()\n        stream.pipe(fs.createWriteStream('medium-closure.heapsnapshot'))\n    }\n    if (index === 50) {\n        const stream = require('v8').getHeapSnapshot()\n        stream.pipe(fs.createWriteStream('big-closure.heapsnapshot'))\n    }\n    res.send('Hello Node');\n});\n\napp.listen(3001);\n```\n\n## Analyze Report\n\nThere are two types of reports: single report and compare report.\n\n### Single Report\n\n```yml\nAnalyze Report with single\nOnly show nodes with more than 20 occurrences\nMemory retained by constructor type\nclosure: 156409.05 MB\n\nObject: 156408.32 MB\n\nsystem / Context: 154881.33 MB\n\narray: 4579.70 MB\n\nsynthetic: 1533.60 MB\n\nArray: 1526.16 MB\n\nWeakMap: 1526.01 MB\n\n(compiled code): 2.96 MB\n\nstring: 2.10 MB\n\nThere are some nodes that are duplicated too many times\nsomeMethod @70761: 202(memoryleak - demo / closure / index.js)\nHttpError @95957: 44(node_modules / http - errors / index.js)\n\nparse @89241: 33(node_modules / ms / index.js)\n\nClientError @50469: 31(node_modules / http - errors / index.js)\n\nindexOf @49211: 27(node_modules / object - inspect / index.js)\n\nsend @126827: 23(node_modules / send / index.js)\n\nresolve @98543: 23(node_modules / express / lib / view.js)\n```\n\n### Compare Report\n\n```yml\nAnalyze Report with compare\nOnly show nodes with more than 20 occurrences\nAdditional nodes by constructor type\n    (compiled code): 242\n\nArrayBuffer: 127\n\nsystem / JSArrayBufferData: 127\n\nBuffer: 126\n\nNode / std::basic_string: 78\n\nclosure: 69\n\nArray: 46\n\narray: 44\n\nsystem / Context: 34\n\nObject: 29\n\nBigger nodes by constructor type\n    (compiled code): 48\nclosure: 25\n\nBigger nodes by increased size\n@1: +83.54 MB\nObject @6613: +76.30 MB\n\nArray @154471: +76.30 MB\n\nArray @154499: +76.30 MB\n\napp @6603: +76.30 MB(node_modules / .pnpm / express @4 .18 .2 / node_modules / express / lib / express.js)\n\nrouter @6533: +76.30 MB(node_modules / .pnpm / express @4 .18 .2 / node_modules / express / lib / router / index.js)\n\nclosureLeak @6481: +76.30 MB(memoryleak - demo / closure / index.js)\n\nRoute @6511: +76.30 MB\n\nLayer @6517: +76.30 MB\n\nLayer @6497: +76.30 MB\n\nServer @6609: +76.30 MB\n\nsystem / Context @6483: +76.30 MB\n```\n\n## Implemented Features \n\n🚀 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 ✨\n\n| Milestone | Status |\n|-----------|--------|\n| Parse V8 snapshot to generate complete node information | 🚀 |\n| View node source location and constructor | 🚀 |\n| Generate analysis reports | 🚀 |\n| Frontend visualization support | 🚀 |\n| Filter nodes by ID and name | 🚀 |\n| Filter number of nodes and view detailed node references | 🚀 |\n| Filter reference depth and number of references | 🚀 |\n| Compare two snapshot files | 🚀 |\n| Support two comparison types: new nodes/increased GC size | 🚀 |\n| Automatically filter non-business nodes based on node count | 🚀 |\n| Support uploading local serialized JSON files | 🚀 |\n| Implement `Wasm + WebWorker` parsing to avoid site unresponsiveness | 🚀 |\n| Optimize parsing performance and reduce memory usage | 🚀 |\n\n## Why Rust\n\nParsing V8 memory snapshots involves a lot of computational operations. CPU-intensive scenarios are inherently not JavaScript's strong suit.\n\nAfter 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.\n\nRust 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.\n\nThis 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.\n\nFinally, Rust's official WebAssembly support is excellent, allowing us to easily compile Rust code to WebAssembly for browser use.\n\n## Handling Parse Timeout Issues\n\nFor very large files, you may encounter Wasm memory overflow or long parse times. If this occurs, try using `Safari` or `Firefox` browsers.\n\n## Contact\n\nThe prohect has been updating, if you have any questions or suggestions, please submit an [issue](https://github.com/zhangyuang/v8-profiler-rs/issues)\n\n\u003cdiv style=\"display:flex\"\u003e\n\u003cimg src=\"https://res.wx.qq.com/op_res/Nv12X2und927FEOvJ5iflzX-WBW07GSC22kumTCiShZnudKpG0jMuRs70ecHQb3Hy1QjjaASNzyOuMgHr43Wpw\" width=\"300\"\u003e\n\n### How to sponsor me\n\nThere are two ways to sponsor me both Alipay and WeChat\n\nEth address: 0x87a2575a5d4dbD5f965e3e3a3d20641BC9a5d192\n\n\u003cdiv style=\"display:flex\"\u003e\n  \u003cimg src=\"https://res.wx.qq.com/shop/public/2025-02-12/d50454c8-65f0-4a81-956b-b8837c187364.jpg\" width=200\u003e\n  \u003cimg src=\"https://res.wx.qq.com/op_res/9jSx7WJn6FBlfQ0ColL4hnvX91D9MlB_XPCgLFM527qknHp0utXZkLah6MYcumdVejK4884dvgkY0NIbBLPrYg\" width=200\u003e\n\u003c/div\u003e \n\n## How to use\n\nOpen the [online demo](https://v8.ssr-fc.com/) and upload the `heapsnapshot` file. You can upload one or two files for comparison.\n\nThere will render heapsnapshot nodes in web page.\n\nThe node fields are as follows:\n\n```js\n{\n    \"node_type\": string; // node type\n    \"name\": string; // node name\n    \"id\": number; // node id\n    \"size\": number; // node self size\n    \"edge_count\": number; // node edge count\n    \"retained_size\": number; // node retained size, the free size of the node after GC\n    \"pt\": number; // the ratio of self size / retained size\n    \"edges\": {\n        \"edge_type\": string; // edge type\n        \"to_node\": number; // the id of the node that the edge points to\n        \"name_or_index\": string; // the name or index（for array） of the edge\n    } [];\n    \"source\": string; // the source file of the node\n    \"constructor\": string; // the constructor of the node\n    \"percent\": string; // the retained size ratio of the node\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyuang%2Fv8-profiler-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangyuang%2Fv8-profiler-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyuang%2Fv8-profiler-rs/lists"}