Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cleanheap

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cleanheap - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

2

package.json
{
"name": "cleanheap",
"version": "0.0.4",
"version": "0.1.0",
"description": "A tool for scrubbing Weak retainer paths from a heap snapshot",

@@ -5,0 +5,0 @@ "main": "src/index.ts",

@@ -106,4 +106,4 @@ import chalk from 'chalk';

const fieldSliceSize = nodeFields.length;
const edgeCount = this.data.snapshot.edge_count;
const edgeFieldsCount = this.data.snapshot.meta.edge_fields.length;
const edgeCount = this.nodeOffsets.edge_count;
const data = this.data;

@@ -117,5 +117,6 @@

(startOffset: number, endOffset: number) => {
const start = nextEdgeIndex
const ownedEdgeCount = getField(nodes, startOffset, edgeCount);
nextEdgeIndex = nextEdgeIndex + ownedEdgeCount + edgeFieldsCount;
const start = nextEdgeIndex;
const ownedEdgeCount = nodes[startOffset + edgeCount];
nextEdgeIndex = nextEdgeIndex + ownedEdgeCount * edgeFieldsCount;
totalObjects++;

@@ -135,3 +136,4 @@

// second pass, remove any edges that are null
this.data.edges = this.data.edges.filter((v: number | null) => v !== null);;
// this is handled during serialization for performance reasons
// this.data.edges = this.data.edges.filter((v: number | null) => v !== null);;

@@ -151,2 +153,5 @@ if (weakRetainers > 0) {

for (let i = edgeStart; i < edgeEnd; i++) {
if (i >= edges.length) {
throw new Error(`Edge index ${i} is out of bounds!`);
}
edges[i] = null as unknown as number;

@@ -178,6 +183,2 @@ }

function getField(nodes: number[], offset: number, index: number): number {
return nodes[offset + index];
}
/**

@@ -201,2 +202,5 @@ * Allows us to iterate a large array in chunks

const writer = outputFile.writer();
const nodeFieldsLength = data.snapshot.meta.node_fields.length;
const edgeFieldsLength = data.snapshot.meta.edge_fields.length;

@@ -207,3 +211,3 @@ // write the header

data.snapshot = null as unknown as any;
writer.write(`{\n"snapshot": ${content}\n`);
writer.write(`{\n"snapshot":${content}\n`);
writer.flush();

@@ -217,7 +221,13 @@ content = ''; // free up memory

process.stdout.write(chalk.grey(`\t${chalk.white('·')}\t\t🔸 ...writing Snapshot nodes`));
content = JSON.stringify(data.nodes);
writer.write(`,"nodes":[`);
for (let i = 0; i < data.nodes.length; i++) {
writer.write(
i === 0 ? String(data.nodes[i]) :
(i + 1) % nodeFieldsLength === 0 ? `,${data.nodes[i]}\n`
: `,${data.nodes[i]}`
);
}
writer.write(`]\n`);
writer.flush();
data.nodes = null as unknown as any;
writer.write(`,"nodes": ${content}\n`);
writer.flush();
content = ''; // free up memory
Bun.gc(true);

@@ -229,7 +239,16 @@ logCompletion(chalk.grey(`\t${chalk.white('·')}\t\t${chalk.green('▶')} Snapshot nodes`));

process.stdout.write(chalk.grey(`\t${chalk.white('·')}\t\t🔸 ...writing Snapshot edges`));
content = JSON.stringify(data.edges);
writer.write(`,"edges":[`);
for (let i = 0; i < data.edges.length; i++) {
if (data.edges[i] === null) {
continue;
}
writer.write(
i === 0 ? String(data.edges[i]) :
(i + 1) % edgeFieldsLength === 0 ? `,${data.edges[i]}\n`
: `,${data.edges[i]}`
);
}
writer.write(`]\n`);
writer.flush();
data.edges = null as unknown as any;
writer.write(`,"edges": ${content}\n`);
writer.flush();
content = ''; // free up memory
Bun.gc(true);

@@ -239,13 +258,2 @@ logCompletion(chalk.grey(`\t${chalk.white('·')}\t\t${chalk.green('▶')} Snapshot edges`));

// write the strings
process.stdout.write(chalk.grey(`\t${chalk.white('·')}\t\t🔸 ...writing Snapshot strings`));
content = JSON.stringify(data.strings);
data.strings = null as unknown as any;
writer.write(`,"strings": ${content}\n`);
writer.flush();
content = ''; // free up memory
Bun.gc(true);
logCompletion(chalk.grey(`\t${chalk.white('·')}\t\t${chalk.green('▶')} Snapshot strings`));
logMemory();
// write everything else

@@ -267,2 +275,23 @@ process.stdout.write(chalk.grey(`\t${chalk.white('·')}\t\t🔸 ...writing Snapshot Infos`));

// write the strings
process.stdout.write(chalk.grey(`\t${chalk.white('·')}\t\t🔸 ...writing Snapshot strings`));
writer.write(`,"strings":[`);
if (data.strings.length) {
content = data.strings.shift()!;
writer.write(`${JSON.stringify(content)}\n`);
}
while (data.strings.length) {
content = data.strings.shift()!;
writer.write(`,${JSON.stringify(content)}\n`);
}
writer.write(`]\n`);
writer.flush();
data.strings = null as unknown as any;
content = ''; // free up memory
Bun.gc(true);
logCompletion(chalk.grey(`\t${chalk.white('·')}\t\t${chalk.green('▶')} Snapshot strings`));
logMemory();
// close the file

@@ -278,4 +307,2 @@ writer.write('}\n');

async function main() {

@@ -282,0 +309,0 @@ const inputFilePath = Bun.argv[2];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc