Account for Map/Set retained strings in JS_ComputeMemoryUsage, or document partial accounting
I maintainer di solito rispondono entro 5 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 30/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- c, javascript
- Ambito
- observability
Direzione di ricerca
Start with JS_ComputeMemoryUsage in quickjs.c, especially the opaque-class TODO near lines 6871-6889, and check how Map and Set storage is reached from the GC object list. Reproduce with the Map/Set/Array script in the issue to confirm that retained strings are missed. Done means either Map/Set keys and values are counted with shared references handled, or the API docs state that these contents are not traversed. The maintainer has not chosen between the two, so confirm the direction before writing code.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Reporting gap
JS_ComputeMemoryUsage() appears to omit strings that are strongly retained only through Map or Set entries. The same strings stored in an Array are counted.
The current source already lists these opaque container classes as a TODO. This issue is intended to track implementing that accounting, or documenting the limitation on the API. It is not a claim of a memory leak or a memory-limit bypass.
Reproducer
Tested with the Bellard QuickJS 2025-09-13 lineage distributed by [email protected] (release-sync WebAssembly). I have not independently run a native C build.
npm install [email protected]
node repro.mjs
import { getQuickJS } from 'quickjs-emscripten';
const QuickJS = await getQuickJS();
for (const kind of ['Map', 'Set', 'Array']) {
const runtime = QuickJS.newRuntime();
const context = runtime.newContext();
function usage() {
const h = runtime.computeMemoryUsage();
try { return context.dump(h); } finally { h.dispose(); }
}
try {
usage(); // Warm the wrapper's system context before taking the baseline.
const before = usage();
const code = kind === 'Map'
? "globalThis.keep = new Map(); for (let i=0;i<128;i++) keep.set(i,'x'.repeat(8192)+i); keep.size;"
: kind === 'Set'
? "globalThis.keep = new Set(); for (let i=0;i<128;i++) keep.add('x'.repeat(8192)+i); keep.size;"
: "globalThis.keep = []; for (let i=0;i<128;i++) keep.push('x'.repeat(8192)+i); keep.length;";
const result = context.evalCode(code);
if (result.error) {
const error = context.dump(result.error); result.error.dispose();
throw new Error(JSON.stringify(error));
}
const entries = context.dump(result.value); result.value.dispose();
const after = usage();
console.log({kind, entries,
byteDelta: after.memory_used_size - before.memory_used_size,
strCount: after.str_count, strBytes: after.str_size});
} finally { context.dispose(); runtime.dispose(); }
}
Observed
Each container remains reachable via globalThis.keep and reports 128 entries:
| Container | memory_used_size increase |
str_count |
|---|---|---|
| Map | 293 bytes | 0 |
| Set | 293 bytes | 0 |
| Array | 1,052,255 bytes | 128 |
The values are 128 distinct strings of roughly 8 KiB each. Only the container changes. Ordinary object values may still be counted via the runtime GC list; the example specifically demonstrates missing retained strings.
Expected / request
Account for Map/Set backing storage and retained keys/values, with appropriate handling of shared references, or clearly document that this API does not traverse these contents. This matters when using snapshots to diagnose retained memory: a live Map containing about 1 MiB of strings otherwise appears almost unchanged.
Relevant source: JS_ComputeMemoryUsage opaque-class TODO. The wrapper delegates to that core function.
Related but different: quickjs-emscripten #206 and PR #207 concern allocator / malloc_usable_size accounting. They do not implement this Map/Set content traversal. I searched open/closed issues and PRs in both repositories and did not find an existing report for this specific gap.
- Lingua principale
- C
- Stelle
- 11.1k
- Fork
- 1.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bellard/quickjs
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
I maintainer di solito rispondono entro 5 giorni
-
RegExp: patterns with more than 255 capture groups fail with "too many captures"Forse già presa @andreasrosdal l’ha presa 3 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
bellard/quickjs#624 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
bellard/quickjs#620 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
(comment on #611) `function g(a, d = (a = 10)) { return a; }` returns the argument instead of 10Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 5 giorni
-
`{ ..."ab" }` is `{}`; a throw in a `for await` body does not wait for the iterator's return()Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
bellard/quickjs#611 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
Tutte le issue di bellard/quickjs
Issue simili
-
documentation good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
JulianKemmerer/PipelineC#409 ·
-
Linux build fails without libspeechd-dev, which INSTALL.md doesn't list and CMake reports as foundAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
GXF: heap buffer overflow in parse_ad_cdp() — unbounded cc_count in CDP cc data sectionForse già presa @pranayr710 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CCExtractor/ccextractor#2498 ·
I maintainer di solito rispondono entro 1 giorno