Skip to content

Latest commit

 

History

History
177 lines (156 loc) · 15.2 KB

ALLOCATIONS.md

File metadata and controls

177 lines (156 loc) · 15.2 KB

ALLOCATIONS: what one parse allocates, per target (auto-generated)

The gate alloc-work (test/alloc-work.ts) regenerates this file and fails when it differs: an allocation more or an allocation fewer than recorded both fail, so every change shows in this diff. The counts are exact: TS target and emitted JS parser by instrumentation of the emitted module (test/alloc-instrument.ts), Go by runtime.MemStats with the collector off. Bytes: Go exact (TotalAlloc); TS / JS modeled from V8's layout (pointer compression; the model is in test/alloc-instrument.ts; the gate prints a measured heapUsed delta beside it). One warm parse runs before the measured one; what a module builds once is not counted.

Go rows measured with go1.27.4. Which function an allocation is attributed to depends on the toolchain (one commit: a 16 B slice growth in (*engine).matchLit under go1.27.4, in (*engine).finish under go1.26.11), so the rows hold for this toolchain only. CI installs it (actions/setup-go, .github/workflows/ci.yml); with another one the Go rows are NOT RUN.

Inputs (locked npm packages): acorn@8.16.0 dist/acorn.js, typescript@5.9.3 lib/lib.es5.d.ts and lib/_tsserver.js (also repeated 4×: per-token counts must not grow with size).

Modes. TS target: parse(src) and parseWith(src, cstBuilder): one engine, run with the CST builder; parse adds no step of its own. JS target: fresh = a new createParser() per parse, reuse = one parser, its document reused. Go: fresh = a new CstBuilder per ParseWith, reuse = one kept. RESULT = what the returned tree holds (TS: objects reachable from it; Go fresh: the final capacity of Nodes / Kids / Toks); OVERHEAD = everything else, garbage once the parse returns. Tokens: each target's own tokenize count. Nodes: rule nodes of the result (JS, Go: the arena's node count).

Per parse

target grammar input mode tokens nodes allocations per token per node bytes B per token B per node result allocs result bytes overhead bytes
ts typescript acorn.js parse 42,209 28,638 142,392 3.37 4.97 4,694,832 111.2 163.9 79,491 2,313,619 2,381,213
ts typescript acorn.js parseWith 42,209 28,638 142,392 3.37 4.97 4,694,832 111.2 163.9 79,491 2,313,619 2,381,213
ts typescript lib.es5.d.ts parse 13,659 7,182 43,954 3.22 6.12 1,441,312 105.5 200.7 20,313 591,395 849,917
ts typescript lib.es5.d.ts parseWith 13,659 7,182 43,954 3.22 6.12 1,441,312 105.5 200.7 20,313 591,395 849,917
ts typescript _tsserver.js parse 4,932 3,139 16,056 3.26 5.12 540,652 109.6 172.2 8,673 252,250 288,402
ts typescript _tsserver.js parseWith 4,932 3,139 16,056 3.26 5.12 540,652 109.6 172.2 8,673 252,250 288,402
ts typescript _tsserver.js ×4 parse 19,728 12,553 64,145 3.25 5.11 2,117,056 107.3 168.6 34,686 1,008,865 1,108,191
ts typescript _tsserver.js ×4 parseWith 19,728 12,553 64,145 3.25 5.11 2,117,056 107.3 168.6 34,686 1,008,865 1,108,191
ts javascript acorn.js parse 42,051 28,638 142,372 3.39 4.97 4,696,156 111.7 164.0 79,491 2,313,271 2,382,885
ts javascript acorn.js parseWith 42,051 28,638 142,372 3.39 4.97 4,696,156 111.7 164.0 79,491 2,313,271 2,382,885
ts javascript _tsserver.js parse 4,928 3,139 16,155 3.28 5.15 543,444 110.3 173.1 8,673 252,132 291,312
ts javascript _tsserver.js parseWith 4,928 3,139 16,155 3.28 5.15 543,444 110.3 173.1 8,673 252,132 291,312
ts javascript _tsserver.js ×4 parse 19,712 12,553 64,541 3.27 5.14 2,128,224 108.0 169.5 34,686 1,008,393 1,119,831
ts javascript _tsserver.js ×4 parseWith 19,712 12,553 64,541 3.27 5.14 2,128,224 108.0 169.5 34,686 1,008,393 1,119,831
js typescript acorn.js fresh 42,209 28,813 5,109 0.12 0.18 13,844,124 328.0 480.5 - - -
js typescript acorn.js reuse 42,209 28,813 4,950 0.12 0.17 233,752 5.5 8.1 - - -
js typescript lib.es5.d.ts fresh 13,659 7,694 7,434 0.54 0.97 2,781,480 203.6 361.5 - - -
js typescript lib.es5.d.ts reuse 13,659 7,694 7,335 0.54 0.95 170,884 12.5 22.2 - - -
js typescript _tsserver.js fresh 4,932 3,221 423 0.09 0.13 1,244,004 252.2 386.2 - - -
js typescript _tsserver.js reuse 4,932 3,221 330 0.07 0.10 15,368 3.1 4.8 - - -
js typescript _tsserver.js ×4 fresh 19,728 12,881 1,415 0.07 0.11 4,635,708 235.0 359.9 - - -
js typescript _tsserver.js ×4 reuse 19,728 12,881 1,293 0.07 0.10 60,512 3.1 4.7 - - -
js javascript acorn.js fresh 42,051 28,958 4,782 0.11 0.17 13,140,440 312.5 453.8 - - -
js javascript acorn.js reuse 42,051 28,958 4,627 0.11 0.16 228,444 5.4 7.9 - - -
js javascript _tsserver.js fresh 4,928 3,263 403 0.08 0.12 1,085,236 220.2 332.6 - - -
js javascript _tsserver.js reuse 4,928 3,263 318 0.06 0.10 15,176 3.1 4.7 - - -
js javascript _tsserver.js ×4 fresh 19,712 13,049 1,362 0.07 0.10 4,788,556 242.9 367.0 - - -
js javascript _tsserver.js ×4 reuse 19,712 13,049 1,245 0.06 0.10 59,744 3.0 4.6 - - -
go typescript acorn.js fresh 42,209 28,638 83 0.00 0.00 9,249,936 219.1 323.0 3 2,072,576 7,177,360
go typescript acorn.js reuse 42,209 28,638 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript acorn.js slim-reuse 42,209 11,490 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript lib.es5.d.ts fresh 13,659 7,233 73 0.01 0.01 2,124,960 155.6 293.8 3 548,864 1,576,096
go typescript lib.es5.d.ts reuse 13,659 7,233 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript lib.es5.d.ts slim-reuse 13,659 3,112 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript _tsserver.js fresh 4,932 3,185 60 0.01 0.02 719,008 145.8 225.7 3 225,280 493,728
go typescript _tsserver.js reuse 4,932 3,185 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript _tsserver.js slim-reuse 4,932 1,372 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript _tsserver.js ×4 fresh 19,728 12,737 78 0.00 0.01 3,714,208 188.3 291.6 3 901,120 2,813,088
go typescript _tsserver.js ×4 reuse 19,728 12,737 0 0.00 0.00 0 0.0 0.0 0 0 0
go typescript _tsserver.js ×4 slim-reuse 19,728 5,485 0 0.00 0.00 0 0.0 0.0 0 0 0
go javascript acorn.js fresh 42,051 28,638 83 0.00 0.00 9,249,936 220.0 323.0 3 2,072,576 7,177,360
go javascript acorn.js reuse 42,051 28,638 0 0.00 0.00 0 0.0 0.0 0 0 0
go javascript acorn.js slim-reuse 42,051 11,490 0 0.00 0.00 0 0.0 0.0 0 0 0
go javascript _tsserver.js fresh 4,928 3,139 60 0.01 0.02 719,008 145.9 229.1 3 225,280 493,728
go javascript _tsserver.js reuse 4,928 3,139 0 0.00 0.00 0 0.0 0.0 0 0 0
go javascript _tsserver.js slim-reuse 4,928 1,367 0 0.00 0.00 0 0.0 0.0 0 0 0
go javascript _tsserver.js ×4 fresh 19,712 12,553 78 0.00 0.01 3,714,208 188.4 295.9 3 901,120 2,813,088
go javascript _tsserver.js ×4 reuse 19,712 12,553 0 0.00 0.00 0 0.0 0.0 0 0 0
go javascript _tsserver.js ×4 slim-reuse 19,712 5,465 0 0.00 0.00 0 0.0 0.0 0 0 0

Where: ts target, parse, typescript grammar, acorn.js (top 15 of 16 sites by bytes)

kind site (literals folded) in functions allocations per token modeled bytes share in result
object { off, end, nl, kid, lid } 1 42,209 1.00 1,350,688 28.8% 0
.slice() → array _hs.slice(b, _n) 1 28,916 0.69 898,372 19.1% 28,638
object { rule, children, offset: off, end } 1 28,915 0.69 809,620 17.2% 28,638
object { tokenType, offset: off, end } 1 25,842 0.61 723,576 15.4% 22,215
array growth toks.push(mk_tok(off, end, pendingNl, kid, lid)) 1 18 0.00 607,924 12.9% 0
.slice() → string src.slice(pos, e) 1 16,248 0.38 300,424 6.4% 0
.slice() → string _src.slice(t.off, u.end) 1 161 0.00 2,576 0.1% 0
.slice() → string _src.slice(_sp[b * _SW + N], _sp[b * _SW + N]) 1 72 0.00 1,240 0.0% 0
array growth localE.push({ tokStart: _sp[s + N]!, tokEnd: pos, ext: Math.max(pos... 1 1 0.00 76 0.0% 0
array growth parenHead.push(!isMember && prevKid === KID_IDENT && !!_phK[prevLid]) 1 1 0.00 76 0.0% 0
array [] 10 4 0.00 64 0.0% 0
object { pos, pendingNl, prevLid, prevKid, hasPrev, bpLid, hasPrev2, paren... 1 1 0.00 60 0.0% 0
object { tokStart: _sp[s + N]!, tokEnd: pos, ext: Math.max(pos, lookEnd())... 1 1 0.00 40 0.0% 0
array [toks, lexFrom(src, N, false, N, N, N, false, false, [], false, fal... 1 1 0.00 32 0.0% 0
closure emit 1 1 0.00 32 0.0% 0

Where: ts target, parseWith, typescript grammar, acorn.js (top 15 of 16 sites by bytes)

kind site (literals folded) in functions allocations per token modeled bytes share in result
object { off, end, nl, kid, lid } 1 42,209 1.00 1,350,688 28.8% 0
.slice() → array _hs.slice(b, _n) 1 28,916 0.69 898,372 19.1% 28,638
object { rule, children, offset: off, end } 1 28,915 0.69 809,620 17.2% 28,638
object { tokenType, offset: off, end } 1 25,842 0.61 723,576 15.4% 22,215
array growth toks.push(mk_tok(off, end, pendingNl, kid, lid)) 1 18 0.00 607,924 12.9% 0
.slice() → string src.slice(pos, e) 1 16,248 0.38 300,424 6.4% 0
.slice() → string _src.slice(t.off, u.end) 1 161 0.00 2,576 0.1% 0
.slice() → string _src.slice(_sp[b * _SW + N], _sp[b * _SW + N]) 1 72 0.00 1,240 0.0% 0
array growth localE.push({ tokStart: _sp[s + N]!, tokEnd: pos, ext: Math.max(pos... 1 1 0.00 76 0.0% 0
array growth parenHead.push(!isMember && prevKid === KID_IDENT && !!_phK[prevLid]) 1 1 0.00 76 0.0% 0
array [] 10 4 0.00 64 0.0% 0
object { pos, pendingNl, prevLid, prevKid, hasPrev, bpLid, hasPrev2, paren... 1 1 0.00 60 0.0% 0
object { tokStart: _sp[s + N]!, tokEnd: pos, ext: Math.max(pos, lookEnd())... 1 1 0.00 40 0.0% 0
array [toks, lexFrom(src, N, false, N, N, N, false, false, [], false, fal... 1 1 0.00 32 0.0% 0
closure emit 1 1 0.00 32 0.0% 0

Where: js target, fresh, typescript grammar, acorn.js (top 15 of 55 sites by bytes)

kind site (literals folded) in functions allocations per token modeled bytes share in result
new Array → array new Array(tokN + N) 1 30 0.00 5,065,920 36.6% -
new Int32Array → typed array new Int32Array(kidCap) 1 9 0.00 2,753,088 19.9% -
new Int32Array → typed array new Int32Array(tokN + N) 1 10 0.00 1,689,040 12.2% -
new Int32Array → typed array new Int32Array(rowCap) 1 16 0.00 1,573,888 11.4% -
new Int32Array → typed array new Int32Array(tkCap) 2 8 0.00 983,552 7.1% -
new Uint8Array → typed array new Uint8Array(tkCap) 2 16 0.00 492,544 3.6% -
new Int32Array → typed array new Int32Array(rows) 1 8 0.00 262,656 1.9% -
new Uint16Array → typed array new Uint16Array(tkCap) 2 4 0.00 246,016 1.8% -
new Int32Array → typed array new Int32Array(rows * N) 1 3 0.00 196,800 1.4% -
new Uint8Array → typed array new Uint8Array(rowCap) 1 6 0.00 147,840 1.1% -
new Uint16Array → typed array new Uint16Array(rowCap) 1 2 0.00 98,432 0.7% -
.exec() → array LXRE_10_Number.exec(source) 1 1,719 0.04 96,280 0.7% -
.exec() → array LXRE_3_LineComment.exec(source) 1 784 0.02 46,972 0.3% -
.exec() → array LXRE_11_String.exec(source) 1 738 0.02 44,016 0.3% -
new Int32Array → typed array new Int32Array(N) 2 2 0.00 32,896 0.2% -

Where: js target, reuse, typescript grammar, acorn.js (top 15 of 15 sites by bytes)

kind site (literals folded) in functions allocations per token modeled bytes share in result
.exec() → array LXRE_10_Number.exec(source) 1 1,719 0.04 96,280 41.2% -
.exec() → array LXRE_3_LineComment.exec(source) 1 784 0.02 46,972 20.1% -
.exec() → array LXRE_11_String.exec(source) 1 738 0.02 44,016 18.8% -
.slice() → string docFlat.slice(a, b) 1 1,255 0.03 20,220 8.7% -
.exec() → array LXRE_6_HexNumber.exec(source) 1 234 0.01 13,272 5.7% -
.exec() → array LXRE_4_BlockComment.exec(source) 1 195 0.00 11,740 5.0% -
.exec() → array LXRE_12_Regex.exec(source) 1 15 0.00 888 0.4% -
.exec() → array LXRE_1_JSDoc.exec(source) 1 2 0.00 120 0.1% -
array growth parenHeadStack.push(_ph) 1 1 0.00 76 0.0% -
array [] 15 2 0.00 32 0.0% -
closure prevIsValue 1 1 0.00 32 0.0% -
closure tkPush 1 1 0.00 32 0.0% -
array [N] 2 1 0.00 28 0.0% -
array [source] 1 1 0.00 28 0.0% -
.slice() → array lexEmptyPops.slice() 1 1 0.00 16 0.0% -

Where: go target, fresh, typescript grammar, acorn.js (top 5 of 5 sites by bytes)

site (innermost function in the parser package) allocations bytes share
(*engine).finish 47 5,829,088 63.0%
lexFrom.func2 26 3,413,248 36.9%
(*engine).pushLeaf 6 7,424 0.1%
(*engine).matchTok 3 112 0.0%
(*engine).parseProgram 1 64 0.0%

Where: go target, reuse, typescript grammar, acorn.js (top 0 of 0 sites by bytes)

site (innermost function in the parser package) allocations bytes share

Where: go target, slim-reuse, typescript grammar, acorn.js (top 0 of 0 sites by bytes)

site (innermost function in the parser package) allocations bytes share