https://github.com/ntrotner/js-heap-comparator
Compare heaps from different JS runtimes
https://github.com/ntrotner/js-heap-comparator
heaps javascript memory-leak v8
Last synced: about 1 month ago
JSON representation
Compare heaps from different JS runtimes
- Host: GitHub
- URL: https://github.com/ntrotner/js-heap-comparator
- Owner: ntrotner
- License: mit
- Created: 2025-02-09T17:24:14.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-17T22:11:35.000Z (about 2 months ago)
- Last Synced: 2025-04-02T00:09:38.527Z (about 1 month ago)
- Topics: heaps, javascript, memory-leak, v8
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/js-heap-comparator
- Size: 287 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-heap-comparator
[](https://github.com/ntrotner/js-heap-comparator/actions/workflows/release.yml)
[](https://www.npmjs.com/package/js-heap-comparator)
![]()
> Compare JS heaps from engines like V8, where the heaps are sourced from different runtimes.
Compatible with heap outputs from Chrome Developer Tools and parsing techniques from [Memlab](https://facebook.github.io/memlab/)
## Install
```bash
npm install js-heap-comparator --save-dev
```
or
```bash
yarn add js-heap-comparator --dev
```## Usage
Check out [examples/compare-heaps.js](examples/compare-heaps.js) for a quick-start.
It's recommended to use the `--max-old-space-size=8192` flag when running the script to avoid memory issues, especially when multiple threads are used.
### Option: `presenterFilePath`
Outputs are saved in the `presenterFilePath` directory. Any returns from the compare function are not planned due to the excessive use of memory.
- `$presenterFilePath/statistics.json`: Contains the statistics of the comparison, e.g. the number of objects, the number of objects that are the same, the number of objects that are different, etc.
- `$presenterFilePath/perfect-match.json`: Contains the objects that are the same in both heap files.
- `$presenterFilePath/next-best-match.json`: Contains the objects that are similar in both heap files.
- `$presenterFilePath/disjunct-nodes.json`: Contains the objects that are different in both heap files.### Option: `activePresenter`
Toggles the type of presenter to output. The least memory intensive is `statistics`, as only the metadata is saved.
The presenter `disjunctNodes` outputs all nodes that couldn't be matches with one another.
Presenters `perfectMatch` and `nextBestMatch` are bound to change to output matches in an efficient way.```javascript
activePresenter: {
statistics: true,
perfectMatch: false,
nextBestMatch: false,
disjunctNodes: false,
}
```### Option: `nextBestMatchObjectThreshold`
Input value between `0.0` and `1.0`. Defines threshold for next best match algorithm, which ranks the similarity of serializable objects.
It's recommended to stay above `0.5` for large heaps.### Option: `nextBestMatchObjectPropertyThreshold`
Input value between `1` and `Infinity`. Defines the amount of properties to compare in the next best match algorithm.
This allows for optimized comparison times, as serialized objects can be deeply nested and cause unnecessary long execution times.
For larger disjunct sets it's recommended to set it between `2500` and `5000`.### Option: `threads`
Input value `>= 1`. Used to parallelize next best match algorithm. Adds large memory overhead due to inter-process communication.
It's recommended to keep it low between `1` and `4`.```javascript
import { V8Comparator } from 'js-heap-comparator';const comparator = new V8Comparator();
heapComparator.initialize({
activePresenter: {
statistics: true,
perfectMatch: false,
nextBestMatch: false,
disjunctNodes: false,
},
presenterFilePath: '/path/to/output/results',
nextBestMatchObjectThreshold: 0.7,
nextBestMatchObjectPropertyThreshold: 10000,
threads: 1
});
heapComparator.compare('current_heapfile.json', 'next_heapfile.json');
```