Repository navigation
perf(formatter)!: reduce peak memory during formatting - #1827
magic-akari wants to merge 1 commit into
Conversation
## Motivation Growing instruction buffers in the formatting arena keeps discarded allocations live until formatting finishes. The Prettier adapter also holds decoded instructions while building the corresponding Docs. ## Changes - Reuse temporary instruction buffers, reserve space for statement sequences, and bulk-copy fragments that need arena storage. - Print JavaScript and TypeScript directly from the root buffer and reserve output capacity using the source size. - Replace `ast_to_doc` with `ast_to_writer`. Call `Writer::finish` when a document must outlive its writer. - Index encoded fragment ranges and references before building Prettier Docs directly from the buffer.
Deploying swc-next with
|
| Latest commit: |
646f9c1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7c19a317.swc-next.pages.dev |
| Branch Preview URL: | https://perf-formatter-memory.swc-next.pages.dev |
Binary size diffLinux x64 GNU · release · uncompressed, stripped bindings. Merge:
|
Gungraun benchmark diffBase SHA: f6f4151 Values are shown as Download the raw Gungraun and Valgrind data (retained for 90 days). Callgrind metric changesCallgrind instruction counts (Ir) for the compare and base revisions. Values are shown as compare / base in K (1,000), truncated to whole thousands. Multi-part profiles use the part numbers from Gungraun and include an aggregated Total. New and Removed identify benchmarks that exist on only one side; the missing value is shown as a dash. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged. Formatter
Generator
Minifier
Parser
Semantic
Transform
Type strip
Visit
Benchmark results |
JavaScript API Gungraun benchmark diffBase: Values are shown as Download the raw Gungraun and Valgrind data (retained for 90 days). Callgrind metric changesMedian instruction counts from three processes, shown as compare / base in K (1,000), truncated to whole thousands. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged or overlapping ranges (inconclusive). JIT disabled (--jitless); predictable mode enabled (--predictable). Counts are not wall time. Exact counts, ranges and profiles are retained in artifacts. Generate
Lang
Parse
Source type
Walk
Benchmark resultsExact instruction counts: median (min–max).
|
Motivation
Growing instruction buffers in the formatting arena can keep old allocations live until the session ends. The Prettier adapter also holds decoded instructions in memory while it builds Docs. Both costs increase peak memory on large files.
Changes
swc_next_formatter_js::ast_to_docwithast_to_writer. CallWriter::finish()when the document needs to outlive its writer.Compared with
main, native CLI peak RSS on macOS arm64 fell from 182.4 to 97.1 MiB fortypescript.jsand from 38.0 to 31.2 MiB for Three.js.