Skip to content

Commit 96b2ecc

Browse files
committed
chore: eslint errors
1 parent 5915ff1 commit 96b2ecc

3 files changed

Lines changed: 42 additions & 22 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default defineConfig([
3737
'puppeteer.config.cjs',
3838
'eslint.config.mjs',
3939
'rollup.config.mjs',
40+
'skills/memory-leak-debugging/references/compare_snapshots.js',
4041
],
4142
},
4243
},

skills/memory-leak-debugging/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This skill provides expert guidance and workflows for finding, diagnosing, and f
1111

1212
- **Prefer `memlab`:** Do NOT attempt to read raw `.heapsnapshot` files directly, as they are extremely large and will consume too many tokens. Always recommend and use `memlab` to process snapshots and identify leak traces.
1313
- **Isolate the Leak:** Determine if the leak is in the browser (client-side) or Node.js (server-side).
14-
- **Common Culprits:** Look for detached DOM nodes, unhandled closures, global variables, event listeners not being removed, and caches growing unbounded. *Note: Detached DOM nodes are sometimes intentional caches; always ask the user before nulling them.*
14+
- **Common Culprits:** Look for detached DOM nodes, unhandled closures, global variables, event listeners not being removed, and caches growing unbounded. _Note: Detached DOM nodes are sometimes intentional caches; always ask the user before nulling them._
1515

1616
## Workflows
1717

@@ -42,7 +42,9 @@ When you have found a leak trace (e.g., via `memlab` output), you must identify
4242
If `memlab` is not available, you MUST use the fallback script in the references directory to compare two `.heapsnapshot` files and identify the top growing objects and common leak types.
4343

4444
Run the script using Node.js:
45+
4546
```bash
4647
node compare_snapshots.js <baseline.heapsnapshot> <target.heapsnapshot>
4748
```
49+
4850
The script will analyze and output the top growing objects by size and highlight the 3 most common types of memory leaks (e.g., Detached DOM nodes, closures, Contexts) if they are present.
Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
const fs = require('fs');
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as fs from 'node:fs';
28

39
function parseSnapshot(filePath) {
410
console.log(`Loading ${filePath}...`);
@@ -7,36 +13,44 @@ function parseSnapshot(filePath) {
713
const nodes = data.nodes;
814
const nodeFields = data.snapshot.meta.node_fields;
915
const nodeFieldCount = nodeFields.length;
10-
16+
1117
const typeOffset = nodeFields.indexOf('type');
1218
const nameOffset = nodeFields.indexOf('name');
1319
const sizeOffset = nodeFields.indexOf('self_size');
14-
20+
1521
const nodeTypes = data.snapshot.meta.node_types[typeOffset];
16-
22+
1723
const counts = {};
1824
const sizes = {};
19-
25+
2026
for (let i = 0; i < nodes.length; i += nodeFieldCount) {
2127
const typeIdx = nodes[i + typeOffset];
2228
const typeName = nodeTypes[typeIdx];
2329
const nameIdx = nodes[i + nameOffset];
2430
const name = typeof nameIdx === 'number' ? strings[nameIdx] : nameIdx;
2531
const size = nodes[i + sizeOffset];
26-
32+
2733
// Ignore native primitives/arrays that clutter the output unless specifically looking for them
28-
if (typeName === 'string' || typeName === 'number' || typeName === 'array') continue;
29-
34+
if (
35+
typeName === 'string' ||
36+
typeName === 'number' ||
37+
typeName === 'array'
38+
) {
39+
continue;
40+
}
41+
3042
const key = `${typeName}::${name}`;
3143
counts[key] = (counts[key] || 0) + 1;
3244
sizes[key] = (sizes[key] || 0) + size;
3345
}
34-
return { counts, sizes };
46+
return {counts, sizes};
3547
}
3648

37-
const [,, file1, file2] = process.argv;
49+
const [, , file1, file2] = process.argv;
3850
if (!file1 || !file2) {
39-
console.error('Usage: node compare_snapshots.js <baseline.heapsnapshot> <target.heapsnapshot>');
51+
console.error(
52+
'Usage: node compare_snapshots.js <baseline.heapsnapshot> <target.heapsnapshot>',
53+
);
4054
process.exit(1);
4155
}
4256

@@ -50,12 +64,12 @@ try {
5064
const count2 = snap2.counts[key];
5165
const size1 = snap1.sizes[key] || 0;
5266
const size2 = snap2.sizes[key];
53-
67+
5468
if (count2 > count1) {
5569
diffs.push({
5670
key,
5771
countDiff: count2 - count1,
58-
sizeDiff: size2 - size1
72+
sizeDiff: size2 - size1,
5973
});
6074
}
6175
}
@@ -68,12 +82,13 @@ try {
6882
});
6983

7084
// Look for common leak indicators
71-
const commonLeaks = diffs.filter(d =>
72-
d.key.toLowerCase().includes('detached') ||
73-
d.key.toLowerCase().includes('html') ||
74-
d.key.toLowerCase().includes('eventlistener') ||
75-
d.key.toLowerCase().includes('context') ||
76-
d.key.toLowerCase().includes('closure')
85+
const commonLeaks = diffs.filter(
86+
d =>
87+
d.key.toLowerCase().includes('detached') ||
88+
d.key.toLowerCase().includes('html') ||
89+
d.key.toLowerCase().includes('eventlistener') ||
90+
d.key.toLowerCase().includes('context') ||
91+
d.key.toLowerCase().includes('closure'),
7792
);
7893

7994
commonLeaks.sort((a, b) => b.countDiff - a.countDiff);
@@ -87,6 +102,8 @@ try {
87102
});
88103
}
89104
} catch (error) {
90-
console.error('Error parsing snapshots. They might be too large for JSON.parse or invalid.');
105+
console.error(
106+
'Error parsing snapshots. They might be too large for JSON.parse or invalid.',
107+
);
91108
console.error(error.message);
92-
}
109+
}

0 commit comments

Comments
 (0)