You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ALLOCATIONS: what one parse allocates, per target (auto-generated)
A REPORT, not a gate: node test/alloc-work.ts --write writes it and the README auto-regen workflow
(.github/workflows/readme-bench.yml) rewrites it on master. The gate alloc-work checks only the invariants
(per-token counts do not grow with the input; a reused Go builder allocates nothing). 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.
Inputs (locked npm packages): acorn@8.16.0dist/acorn.js, typescript@5.9.3lib/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,251
28,638
159,870
3.78
5.58
5,263,936
124.6
183.8
99,327
2,948,317
2,315,619
ts
typescript
acorn.js
parseWith
42,251
28,638
159,870
3.78
5.58
5,263,936
124.6
183.8
99,327
2,948,317
2,315,619
ts
typescript
lib.es5.d.ts
parse
13,659
7,182
52,393
3.84
7.30
1,712,924
125.4
238.5
28,023
836,284
876,640
ts
typescript
lib.es5.d.ts
parseWith
13,659
7,182
52,393
3.84
7.30
1,712,924
125.4
238.5
28,023
836,284
876,640
ts
typescript
_tsserver.js
parse
4,932
3,139
18,563
3.76
5.91
621,168
125.9
197.9
11,206
333,261
287,907
ts
typescript
_tsserver.js
parseWith
4,932
3,139
18,563
3.76
5.91
621,168
125.9
197.9
11,206
333,261
287,907
ts
typescript
_tsserver.js ×4
parse
19,728
12,553
74,173
3.76
5.91
2,439,120
123.6
194.3
44,818
1,332,916
1,106,204
ts
typescript
_tsserver.js ×4
parseWith
19,728
12,553
74,173
3.76
5.91
2,439,120
123.6
194.3
44,818
1,332,916
1,106,204
ts
javascript
acorn.js
parse
42,051
32,239
166,694
3.96
5.17
5,457,020
129.8
169.3
106,529
3,149,490
2,307,530
ts
javascript
acorn.js
parseWith
42,051
32,239
166,694
3.96
5.17
5,457,020
129.8
169.3
106,529
3,149,490
2,307,530
ts
javascript
_tsserver.js
parse
4,928
3,411
19,197
3.90
5.63
638,752
129.6
187.3
11,750
348,191
290,561
ts
javascript
_tsserver.js
parseWith
4,928
3,411
19,197
3.90
5.63
638,752
129.6
187.3
11,750
348,191
290,561
ts
javascript
_tsserver.js ×4
parse
19,712
13,641
76,709
3.89
5.62
2,509,456
127.3
184.0
46,994
1,392,635
1,116,821
ts
javascript
_tsserver.js ×4
parseWith
19,712
13,641
76,709
3.89
5.62
2,509,456
127.3
184.0
46,994
1,392,635
1,116,821
js
typescript
acorn.js
fresh
42,251
28,813
5,161
0.12
0.18
14,643,756
346.6
508.2
-
-
-
js
typescript
acorn.js
reuse
42,251
28,813
4,992
0.12
0.17
234,424
5.5
8.1
-
-
-
js
typescript
lib.es5.d.ts
fresh
13,659
7,692
7,008
0.51
0.91
2,790,368
204.3
362.8
-
-
-
js
typescript
lib.es5.d.ts
reuse
13,659
7,692
6,907
0.51
0.90
162,260
11.9
21.1
-
-
-
js
typescript
_tsserver.js
fresh
4,932
3,217
429
0.09
0.13
1,340,580
271.8
416.7
-
-
-
js
typescript
_tsserver.js
reuse
4,932
3,217
330
0.07
0.10
15,368
3.1
4.8
-
-
-
js
typescript
_tsserver.js ×4
fresh
19,728
12,865
1,423
0.07
0.11
5,001,916
253.5
388.8
-
-
-
js
typescript
_tsserver.js ×4
reuse
19,728
12,865
1,293
0.07
0.10
60,512
3.1
4.7
-
-
-
js
javascript
acorn.js
fresh
42,051
32,559
4,796
0.11
0.15
14,602,512
347.3
448.5
-
-
-
js
javascript
acorn.js
reuse
42,051
32,559
4,627
0.11
0.14
228,444
5.4
7.0
-
-
-
js
javascript
_tsserver.js
fresh
4,928
3,535
425
0.09
0.12
1,497,812
303.9
423.7
-
-
-
js
javascript
_tsserver.js
reuse
4,928
3,535
318
0.06
0.09
15,176
3.1
4.3
-
-
-
js
javascript
_tsserver.js ×4
fresh
19,712
14,137
1,386
0.07
0.10
6,416,748
325.5
453.9
-
-
-
js
javascript
_tsserver.js ×4
reuse
19,712
14,137
1,245
0.06
0.09
59,744
3.0
4.2
-
-
-
go
typescript
acorn.js
fresh
42,251
28,638
85
0.00
0.00
9,671,168
228.9
337.7
3
2,154,496
7,516,672
go
typescript
acorn.js
reuse
42,251
28,638
0
0.00
0.00
0
0.0
0.0
0
0
0
go
typescript
acorn.js
slim-reuse
42,251
11,491
0
0.00
0.00
0
0.0
0.0
0
0
0
go
typescript
lib.es5.d.ts
fresh
13,659
7,233
75
0.01
0.01
2,289,312
167.6
316.5
3
589,824
1,699,488
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
61
0.01
0.02
759,456
154.0
238.4
3
237,568
521,888
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
79
0.00
0.01
3,841,696
194.7
301.6
3
933,888
2,907,808
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
32,239
85
0.00
0.00
9,671,168
230.0
300.0
3
2,154,496
7,516,672
go
javascript
acorn.js
reuse
42,051
32,239
0
0.00
0.00
0
0.0
0.0
0
0
0
go
javascript
acorn.js
slim-reuse
42,051
11,491
0
0.00
0.00
0
0.0
0.0
0
0
0
go
javascript
_tsserver.js
fresh
4,928
3,411
61
0.01
0.02
759,456
154.1
222.6
3
237,568
521,888
go
javascript
_tsserver.js
reuse
4,928
3,411
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
13,641
81
0.00
0.01
4,554,400
231.0
333.9
3
1,089,536
3,464,864
go
javascript
_tsserver.js ×4
reuse
19,712
13,641
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)