Skip to content

Only pre-size the printer buffer when printing a whole file - #64972

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
jakebailey:printer-grow-whole-file
Oct 27, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
jakebailey:printer-grow-whole-file

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This has been wasting a whole bunch of memory on printing.

Write grew the writer by the full source file length for every call,
including when printing a single type node for typeToString or the
type baselines. Each resulting string then pinned a buffer the size
of the file; for largeControlFlowGraph.ts the types baseline retained
over 3GB this way, which exhausts the 4GB wasm address space.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 19:18
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 26, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 26, 2026
@jakebailey

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) perf test this faster

@typescript-automation

typescript-automation Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
perf test this faster ✅ Started ❌ Results

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow guard preserves whole-file preallocation without changing printed output, and no blocking issues were identified.

No open issues 🎉

What changed in this PR

This PR reduces unnecessary memory allocation in the compiler’s printer by limiting buffer pre-sizing to whole-file printing.

Changes:

  • Pre-size the buffer only when the node being printed is the supplied source file.
  • Avoid reserving whole-file capacity when printing individual nodes.
File Description
tsc/​internal/​printer/​printer.go Restricts source-length buffer preallocation to whole-file printing.

Review effort: Balanced

@typescript-automation

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey), the perf run you requested failed. You can check the log here.

1 similar comment
@typescript-automation

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey), the perf run you requested failed. You can check the log here.

@typescript-automation

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

Provisional hosted-runner results: these VMs are not the dedicated benchmark machines. Results may be noisier and are not comparable to the historical series. For comparisons, both revisions of each scenario ran on the same VM.

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - native
Errors 41 41 ~ ~ ~ p=1.000 n=12
Symbols 88,466 88,466 ~ ~ ~ p=1.000 n=12
Types 79,607 79,607 ~ ~ ~ p=1.000 n=12
Memory Used 109,256k (± 0.09%) 107,805k (± 0.05%) -1,451k (- 1.33%) 107,699k 107,924k p=0.000 n=12
Memory Allocs 2,196,992 (± 0.01%) 2,196,848 (± 0.00%) ~ 2,196,678 2,197,231 p=0.089 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.032s (± 3.85%) 0.032s (± 4.55%) ~ 0.029s 0.036s p=0.671 n=12
Bind Time 0.012s (± 6.46%) 0.012s (± 4.20%) ~ 0.010s 0.013s p=0.446 n=12
Check Time 0.339s (± 0.52%) 0.335s (± 0.39%) -0.004s (- 1.33%) 0.332s 0.339s p=0.000 n=12
Emit Time 0.214s (± 1.75%) 0.210s (± 0.77%) -0.004s (- 1.79%) 0.206s 0.216s p=0.009 n=12
Total Time 0.602s (± 0.68%) 0.593s (± 0.45%) -0.009s (- 1.51%) 0.588s 0.601s p=0.002 n=12
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=12
Symbols 586,520 (± 0.02%) 586,527 (± 0.02%) ~ 586,209 586,747 p=0.989 n=12
Types 241,691 (± 0.00%) 241,693 (± 0.00%) +2 (+ 0.00%) 241,691 241,695 p=0.002 n=12
Memory Used 551,238k (± 0.02%) 551,185k (± 0.02%) ~ 550,981k 551,440k p=0.469 n=12
Memory Allocs 13,073,823 (± 0.07%) 13,074,687 (± 0.07%) ~ 13,067,360 13,121,527 p=0.378 n=12
Config Time 0.017s (± 1.07%) 0.017s ~ ~ ~ p=1.000 n=12
Parse Time 0.192s (± 2.26%) 0.193s (± 4.47%) ~ 0.177s 0.223s p=0.921 n=12
Bind Time 0.055s (± 8.75%) 0.059s (±14.31%) ~ 0.051s 0.082s p=0.887 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 1.179s (± 1.19%) 1.173s (± 1.40%) ~ 1.131s 1.206s p=0.854 n=12
Total Time 1.456s (± 0.92%) 1.455s (± 0.96%) ~ 1.422s 1.483s p=0.920 n=12
arktype - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 685,943 685,943 ~ ~ ~ p=1.000 n=12
Types 939,490 939,490 ~ ~ ~ p=1.000 n=12
Memory Used 533,209k (± 0.01%) 532,539k (± 0.01%) -670k (- 0.13%) 532,339k 532,779k p=0.000 n=12
Memory Allocs 12,770,711 (± 0.01%) 12,769,757 (± 0.01%) ~ 12,768,071 12,772,220 p=0.291 n=12
Config Time 0.002s 0.002s ~ ~ ~ p=1.000 n=12
Parse Time 0.060s (± 3.67%) 0.062s (± 4.06%) ~ 0.055s 0.068s p=0.190 n=12
Bind Time 0.019s (±11.42%) 0.020s (± 9.38%) ~ 0.017s 0.025s p=0.379 n=12
Check Time 1.398s (± 0.42%) 1.409s (± 0.57%) +0.011s (+ 0.80%) 1.387s 1.430s p=0.046 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.520s (± 0.55%) 1.533s (± 0.59%) +0.013s (+ 0.85%) 1.507s 1.554s p=0.040 n=12
mui-docs - native
Errors 11,405 11,405 ~ ~ ~ p=1.000 n=12
Symbols 3,784,027 3,784,027 ~ ~ ~ p=1.000 n=12
Types 1,355,982 1,355,982 ~ ~ ~ p=1.000 n=12
Memory Used 2,198,373k (± 0.07%) 2,199,375k (± 0.06%) ~ 2,196,346k 2,202,722k p=0.370 n=12
Memory Allocs 26,476,877 (± 0.11%) 26,493,525 (± 0.06%) ~ 26,437,562 26,532,993 p=0.114 n=12
Config Time 0.014s (± 1.73%) 0.014s ~ ~ ~ p=0.478 n=12
Parse Time 0.491s (± 2.12%) 0.482s (± 2.44%) ~ 0.449s 0.514s p=0.271 n=12
Bind Time 0.002s (±21.90%) 0.002s (±21.90%) ~ 0.001s 0.002s p=1.000 n=12
Check Time 4.794s (± 0.58%) 4.806s (± 0.69%) ~ 4.700s 4.899s p=0.811 n=12
Emit Time 0.387s (± 8.90%) 0.387s (± 8.75%) ~ 0.335s 0.493s p=0.659 n=12
Total Time 6.478s (± 0.72%) 6.480s (± 0.65%) ~ 6.341s 6.588s p=0.523 n=12
sentry - native
Errors 2 2 ~ ~ ~ p=1.000 n=12
Symbols 4,793,249 4,793,249 ~ ~ ~ p=1.000 n=12
Types 2,607,051 2,607,051 ~ ~ ~ p=1.000 n=12
Memory Used 3,204,946k (± 0.03%) 3,204,399k (± 0.03%) ~ 3,201,348k 3,208,213k p=0.347 n=12
Memory Allocs 75,233,299 (± 0.12%) 75,231,278 (± 0.14%) ~ 74,931,252 75,444,093 p=0.843 n=12
Config Time 0.045s (± 0.94%) 0.045s (± 0.87%) ~ 0.044s 0.046s p=0.603 n=12
Parse Time 0.730s (± 5.17%) 0.739s (± 6.19%) ~ 0.664s 0.904s p=0.920 n=12
Bind Time 0.203s (±12.95%) 0.197s (± 8.68%) ~ 0.174s 0.253s p=0.989 n=12
Check Time 9.588s (± 0.67%) 9.416s (± 0.69%) -0.172s (- 1.80%) 9.276s 9.642s p=0.000 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 10.627s (± 0.74%) 10.460s (± 0.66%) -0.167s (- 1.57%) 10.349s 10.751s p=0.001 n=12
social-app - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,883,075 1,883,075 ~ ~ ~ p=1.000 n=12
Types 1,158,171 1,158,171 ~ ~ ~ p=1.000 n=12
Memory Used 1,057,017k (± 0.02%) 1,056,492k (± 0.02%) -525k (- 0.05%) 1,055,954k 1,057,126k p=0.000 n=12
Memory Allocs 13,583,355 (± 0.19%) 13,586,716 (± 0.33%) ~ 13,532,636 13,775,572 p=0.671 n=12
Config Time 0.014s (± 2.00%) 0.015s (± 2.22%) ~ 0.014s 0.015s p=0.214 n=12
Parse Time 0.239s (± 2.69%) 0.236s (± 1.82%) ~ 0.221s 0.246s p=0.433 n=12
Bind Time 0.056s (±14.66%) 0.059s (±13.74%) ~ 0.047s 0.085s p=0.212 n=12
Check Time 2.172s (± 0.43%) 2.131s (± 0.49%) -0.042s (- 1.93%) 2.106s 2.161s p=0.000 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 2.503s (± 0.78%) 2.459s (± 0.46%) -0.043s (- 1.73%) 2.426s 2.482s p=0.000 n=12
strada-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,184,976 1,184,976 ~ ~ ~ p=1.000 n=12
Types 438,967 438,967 ~ ~ ~ p=1.000 n=12
Memory Used 1,254,441k (± 0.40%) 1,264,052k (± 0.25%) +9,611k (+ 0.77%) 1,254,433k 1,271,359k p=0.003 n=12
Memory Allocs 76,856,941 (± 0.15%) 77,006,138 (± 0.13%) +149,197 (+ 0.19%) 76,850,665 77,301,200 p=0.045 n=12
Config Time 0.004s (± 9.45%) 0.004s (±10.43%) ~ 0.003s 0.005s p=0.057 n=12
Parse Time 0.177s (± 3.33%) 0.180s (± 2.47%) ~ 0.167s 0.189s p=0.434 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 1.196s (± 0.43%) 1.188s (± 0.54%) ~ 1.170s 1.201s p=0.057 n=12
Emit Time 0.213s (± 3.01%) 0.218s (± 2.29%) ~ 0.205s 0.234s p=0.183 n=12
Total Time 14.066s (± 0.75%) 14.000s (± 0.49%) ~ 13.889s 14.223s p=0.164 n=12
strada-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 263,513 263,513 ~ ~ ~ p=1.000 n=12
Types 196,118 196,118 ~ ~ ~ p=1.000 n=12
Memory Used 236,086k (± 0.03%) 236,090k (± 0.03%) ~ 235,956k 236,293k p=0.755 n=12
Memory Allocs 4,287,566 (± 0.01%) 4,287,705 (± 0.01%) ~ 4,286,601 4,288,855 p=0.843 n=12
Config Time 0.001s (±19.81%) 0.001s ~ ~ ~ p=1.000 n=12
Parse Time 0.073s (± 4.60%) 0.073s (± 5.78%) ~ 0.064s 0.083s p=0.700 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 0.596s (± 0.43%) 0.596s (± 0.80%) ~ 0.588s 0.615s p=0.337 n=12
Emit Time 0.100s (± 4.59%) 0.094s (± 2.61%) 🟩-0.006s (- 6.18%) 0.088s 0.101s p=0.027 n=12
Total Time 0.809s (± 0.98%) 0.802s (± 0.69%) ~ 0.781s 0.812s p=0.124 n=12
t3code-server - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 4,350,705 4,350,705 ~ ~ ~ p=1.000 n=12
Types 3,040,691 3,040,691 ~ ~ ~ p=1.000 n=12
Memory Used 2,610,376k (± 0.03%) 2,609,991k (± 0.02%) ~ 2,608,994k 2,611,346k p=0.551 n=12
Memory Allocs 37,317,817 (± 0.06%) 37,319,495 (± 0.07%) ~ 37,271,445 37,388,426 p=0.977 n=12
Config Time 0.005s (± 5.98%) 0.005s 🟩-0.000s (- 7.69%) ~ ~ p=0.037 n=12
Parse Time 0.379s (± 3.36%) 0.383s (± 5.49%) ~ 0.337s 0.441s p=0.766 n=12
Bind Time 0.133s (±10.25%) 0.147s (±10.15%) ~ 0.111s 0.182s p=0.271 n=12
Check Time 11.382s (± 1.47%) 11.230s (± 2.55%) ~ 10.810s 12.243s p=0.101 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 11.915s (± 1.51%) 11.784s (± 2.60%) ~ 11.328s 12.842s p=0.114 n=12
ts-pre-modules - native
Errors 87 87 ~ ~ ~ p=1.000 n=12
Symbols 231,617 231,617 ~ ~ ~ p=1.000 n=12
Types 181,196 181,196 ~ ~ ~ p=1.000 n=12
Memory Used 203,523k (± 0.02%) 203,346k (± 0.02%) -177k (- 0.09%) 203,254k 203,411k p=0.000 n=12
Memory Allocs 1,357,967 (± 0.01%) 1,358,075 (± 0.01%) ~ 1,357,783 1,358,758 p=0.259 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.068s (± 6.48%) 0.070s (± 4.44%) ~ 0.059s 0.076s p=0.223 n=12
Bind Time 0.034s (± 8.03%) 0.032s (± 7.53%) ~ 0.024s 0.039s p=0.701 n=12
Check Time 0.524s (± 1.98%) 0.495s (± 2.09%) 🟩-0.029s (- 5.61%) 0.469s 0.525s p=0.000 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.638s (± 1.88%) 0.607s (± 1.67%) 🟩-0.031s (- 4.82%) 0.586s 0.632s p=0.000 n=12
vscode - native
Errors 10 10 ~ ~ ~ p=1.000 n=12
Symbols 7,281,695 7,281,695 ~ ~ ~ p=1.000 n=12
Types 4,286,835 4,286,835 ~ ~ ~ p=1.000 n=12
Memory Used 5,404,797k (± 0.01%) 5,404,599k (± 0.02%) ~ 5,401,911k 5,407,434k p=0.843 n=12
Memory Allocs 62,554,948 (± 0.01%) 62,549,750 (± 0.01%) ~ 62,541,032 62,564,139 p=0.178 n=12
Config Time 0.069s (± 0.57%) 0.069s (± 0.73%) ~ 0.068s 0.070s p=0.474 n=12
Parse Time 1.272s (± 1.91%) 1.269s (± 1.12%) ~ 1.226s 1.300s p=0.452 n=12
Bind Time 0.420s (± 9.44%) 0.408s (± 5.35%) ~ 0.388s 0.514s p=0.853 n=12
Check Time 11.576s (± 0.54%) 11.396s (± 0.22%) -0.180s (- 1.56%) 11.322s 11.477s p=0.000 n=12
Emit Time 3.906s (± 4.45%) 3.917s (± 3.81%) ~ 3.587s 4.311s p=0.843 n=12
Total Time 17.313s (± 1.12%) 17.129s (± 0.85%) ~ 16.830s 17.530s p=0.143 n=12
webpack - native
Errors 617 617 ~ ~ ~ p=1.000 n=12
Symbols 922,055 922,055 ~ ~ ~ p=1.000 n=12
Types 644,701 644,701 ~ ~ ~ p=1.000 n=12
Memory Used 776,051k (± 0.02%) 745,341k (± 0.02%) 🟩-30,711k (- 3.96%) 745,061k 745,730k p=0.000 n=12
Memory Allocs 6,571,731 (± 0.02%) 6,572,291 (± 0.02%) ~ 6,570,285 6,575,311 p=0.410 n=12
Config Time 0.007s 0.007s ~ ~ ~ p=1.000 n=12
Parse Time 0.199s (± 4.14%) 0.200s (± 4.69%) ~ 0.174s 0.228s p=0.788 n=12
Bind Time 0.063s (± 9.94%) 0.059s (±11.31%) ~ 0.050s 0.089s p=0.181 n=12
Check Time 1.683s (± 0.59%) 1.665s (± 0.44%) -0.018s (- 1.04%) 1.644s 1.684s p=0.005 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.987s (± 0.57%) 1.970s (± 0.67%) ~ 1.944s 2.003s p=0.058 n=12
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 640,494 640,494 ~ ~ ~ p=1.000 n=12
Types 387,992 387,992 ~ ~ ~ p=1.000 n=12
Memory Used 398,392k (± 0.02%) 386,687k (± 0.03%) -11,705k (- 2.94%) 386,391k 387,076k p=0.000 n=12
Memory Allocs 3,990,895 (± 0.07%) 3,992,618 (± 0.09%) ~ 3,980,548 4,000,566 p=0.410 n=12
Config Time 0.002s 0.002s ~ ~ ~ p=1.000 n=12
Parse Time 0.088s (± 3.22%) 0.087s (± 2.58%) ~ 0.081s 0.092s p=0.578 n=12
Bind Time 0.027s (±12.22%) 0.026s (± 8.93%) ~ 0.023s 0.036s p=0.772 n=12
Check Time 0.618s (± 0.96%) 0.611s (± 0.79%) ~ 0.600s 0.625s p=0.071 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.741s (± 0.92%) 0.733s (± 0.77%) ~ 0.718s 0.746s p=0.085 n=12
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • arktype - native
  • mui-docs - native
  • sentry - native
  • social-app - native
  • strada-build-src - native
  • strada-compiler - native
  • t3code-server - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 12
Baseline baseline 12

Developer Information:

Download Benchmarks

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Oct 27, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Oct 27, 2026
Merged via the queue into microsoft:main with commit 1f82f36 Oct 27, 2026
29 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the printer-grow-whole-file branch October 27, 2026 16:30
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants