Rewrites renderArrayInit to avoid rendering expressions twice in the common case of there being one line per expression. Also reduces memory usage with the use of a scratch list for array inits and only storing the widths of expressions in the current section. A lot of logic has also been deduplicated. A few bugs were also fixed.
Closes #35714
Performance Measurements
ReleaseFast
Benchmark 1 (8 runs): ./master-fast fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 666ms ± 3.13ms 663ms ... 673ms 1 (13%) 0%
peak_rss 43.4MB ± 1.11MB 41.9MB ... 45.0MB 0 ( 0%) 0%
cpu_cycles 2.88G ± 6.03M 2.87G ... 2.89G 0 ( 0%) 0%
instructions 8.95G ± 300 8.95G ... 8.95G 0 ( 0%) 0%
cache_references 43.0M ± 174K 42.8M ... 43.4M 0 ( 0%) 0%
cache_misses 3.06M ± 50.3K 2.99M ... 3.12M 0 ( 0%) 0%
branch_misses 16.7M ± 112K 16.5M ... 16.8M 1 (13%) 0%
Benchmark 2 (9 runs): ./branch-fast fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 565ms ± 1.19ms 562ms ... 566ms 1 (11%) ⚡- 15.2% ± 0.4%
peak_rss 42.4MB ± 690KB 41.5MB ... 43.5MB 0 ( 0%) - 2.3% ± 2.2%
cpu_cycles 2.41G ± 5.59M 2.40G ... 2.42G 0 ( 0%) ⚡- 16.2% ± 0.2%
instructions 7.24G ± 165 7.24G ... 7.24G 0 ( 0%) ⚡- 19.1% ± 0.0%
cache_references 41.0M ± 607K 40.3M ... 42.3M 0 ( 0%) ⚡- 4.6% ± 1.1%
cache_misses 2.72M ± 40.5K 2.64M ... 2.76M 0 ( 0%) ⚡- 11.2% ± 1.5%
branch_misses 16.6M ± 125K 16.4M ... 16.7M 0 ( 0%) - 0.8% ± 0.7%
Benchmark 1 (18 runs): ./master-fast fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 291ms ± 2.53ms 287ms ... 298ms 3 (17%) 0%
peak_rss 60.2MB ± 900KB 59.2MB ... 61.8MB 0 ( 0%) 0%
cpu_cycles 1.33G ± 11.5M 1.31G ... 1.36G 2 (11%) 0%
instructions 4.15G ± 259 4.15G ... 4.15G 0 ( 0%) 0%
cache_references 10.9M ± 729K 10.3M ... 13.0M 2 (11%) 0%
cache_misses 394K ± 22.5K 361K ... 428K 0 ( 0%) 0%
branch_misses 4.63M ± 69.8K 4.52M ... 4.73M 0 ( 0%) 0%
Benchmark 2 (24 runs): ./branch-fast fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 213ms ± 1.87ms 210ms ... 220ms 1 ( 4%) ⚡- 26.8% ± 0.5%
peak_rss 60.2MB ± 599KB 59.3MB ... 61.5MB 2 ( 8%) + 0.0% ± 0.8%
cpu_cycles 960M ± 7.24M 947M ... 982M 5 (21%) ⚡- 27.9% ± 0.4%
instructions 2.95G ± 294 2.95G ... 2.95G 0 ( 0%) ⚡- 28.9% ± 0.0%
cache_references 9.80M ± 232K 9.46M ... 10.4M 3 (13%) ⚡- 10.1% ± 2.9%
cache_misses 356K ± 28.7K 292K ... 448K 2 ( 8%) ⚡- 9.7% ± 4.2%
branch_misses 3.78M ± 56.0K 3.67M ... 3.87M 0 ( 0%) ⚡- 18.3% ± 0.8%
ReleaseSafe
Benchmark 1 (6 runs): ./master-safe fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 896ms ± 131ms 839ms ... 1.16s 0 ( 0%) 0%
peak_rss 85.1MB ± 669KB 84.2MB ... 86.0MB 0 ( 0%) 0%
cpu_cycles 3.83G ± 8.13M 3.82G ... 3.84G 0 ( 0%) 0%
instructions 13.0G ± 472 13.0G ... 13.0G 0 ( 0%) 0%
cache_references 86.4M ± 309K 85.8M ... 86.7M 1 (17%) 0%
cache_misses 4.31M ± 333K 4.12M ... 4.99M 0 ( 0%) 0%
branch_misses 15.8M ± 260K 15.5M ... 16.3M 0 ( 0%) 0%
Benchmark 2 (7 runs): ./branch-safe fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 766ms ± 2.12ms 763ms ... 769ms 0 ( 0%) ⚡- 14.5% ± 12.0%
peak_rss 48.8MB ± 623KB 48.1MB ... 49.7MB 0 ( 0%) ⚡- 42.7% ± 0.9%
cpu_cycles 3.19G ± 8.17M 3.18G ... 3.21G 0 ( 0%) ⚡- 16.6% ± 0.3%
instructions 10.3G ± 750 10.3G ... 10.3G 0 ( 0%) ⚡- 20.9% ± 0.0%
cache_references 78.9M ± 404K 78.2M ... 79.2M 0 ( 0%) ⚡- 8.7% ± 0.5%
cache_misses 5.41M ± 51.7K 5.35M ... 5.47M 0 ( 0%) 💩+ 25.5% ± 6.5%
branch_misses 15.6M ± 102K 15.5M ... 15.8M 0 ( 0%) - 1.3% ± 1.5%
Benchmark 1 (12 runs): ./master-safe fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 432ms ± 1.07ms 430ms ... 433ms 0 ( 0%) 0%
peak_rss 115MB ± 480KB 115MB ... 116MB 1 ( 8%) 0%
cpu_cycles 1.95G ± 3.63M 1.95G ... 1.96G 0 ( 0%) 0%
instructions 6.95G ± 237 6.95G ... 6.95G 3 (25%) 0%
cache_references 25.1M ± 786K 24.3M ... 27.1M 1 ( 8%) 0%
cache_misses 558K ± 17.4K 524K ... 587K 0 ( 0%) 0%
branch_misses 5.11M ± 84.6K 4.98M ... 5.22M 0 ( 0%) 0%
Benchmark 2 (17 runs): ./branch-safe fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 302ms ± 1.38ms 299ms ... 304ms 0 ( 0%) ⚡- 30.1% ± 0.2%
peak_rss 80.9MB ± 577KB 79.8MB ... 81.8MB 0 ( 0%) ⚡- 29.6% ± 0.4%
cpu_cycles 1.37G ± 6.22M 1.35G ... 1.38G 0 ( 0%) ⚡- 29.8% ± 0.2%
instructions 4.75G ± 386 4.75G ... 4.75G 0 ( 0%) ⚡- 31.6% ± 0.0%
cache_references 18.5M ± 308K 18.2M ... 19.4M 0 ( 0%) ⚡- 26.1% ± 1.7%
cache_misses 459K ± 16.7K 431K ... 494K 0 ( 0%) ⚡- 17.6% ± 2.4%
branch_misses 4.01M ± 114K 3.87M ... 4.21M 0 ( 0%) ⚡- 21.4% ± 1.6%
Rewrites `renderArrayInit` to avoid rendering expressions twice in the common case of there being one line per expression. Also reduces memory usage with the use of a scratch list for array inits and only storing the widths of expressions in the current section. A lot of logic has also been deduplicated. A few bugs were also fixed.
Closes #35714
## Performance Measurements
### ReleaseFast
```
Benchmark 1 (8 runs): ./master-fast fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 666ms ± 3.13ms 663ms ... 673ms 1 (13%) 0%
peak_rss 43.4MB ± 1.11MB 41.9MB ... 45.0MB 0 ( 0%) 0%
cpu_cycles 2.88G ± 6.03M 2.87G ... 2.89G 0 ( 0%) 0%
instructions 8.95G ± 300 8.95G ... 8.95G 0 ( 0%) 0%
cache_references 43.0M ± 174K 42.8M ... 43.4M 0 ( 0%) 0%
cache_misses 3.06M ± 50.3K 2.99M ... 3.12M 0 ( 0%) 0%
branch_misses 16.7M ± 112K 16.5M ... 16.8M 1 (13%) 0%
Benchmark 2 (9 runs): ./branch-fast fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 565ms ± 1.19ms 562ms ... 566ms 1 (11%) ⚡- 15.2% ± 0.4%
peak_rss 42.4MB ± 690KB 41.5MB ... 43.5MB 0 ( 0%) - 2.3% ± 2.2%
cpu_cycles 2.41G ± 5.59M 2.40G ... 2.42G 0 ( 0%) ⚡- 16.2% ± 0.2%
instructions 7.24G ± 165 7.24G ... 7.24G 0 ( 0%) ⚡- 19.1% ± 0.0%
cache_references 41.0M ± 607K 40.3M ... 42.3M 0 ( 0%) ⚡- 4.6% ± 1.1%
cache_misses 2.72M ± 40.5K 2.64M ... 2.76M 0 ( 0%) ⚡- 11.2% ± 1.5%
branch_misses 16.6M ± 125K 16.4M ... 16.7M 0 ( 0%) - 0.8% ± 0.7%
```
```
Benchmark 1 (18 runs): ./master-fast fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 291ms ± 2.53ms 287ms ... 298ms 3 (17%) 0%
peak_rss 60.2MB ± 900KB 59.2MB ... 61.8MB 0 ( 0%) 0%
cpu_cycles 1.33G ± 11.5M 1.31G ... 1.36G 2 (11%) 0%
instructions 4.15G ± 259 4.15G ... 4.15G 0 ( 0%) 0%
cache_references 10.9M ± 729K 10.3M ... 13.0M 2 (11%) 0%
cache_misses 394K ± 22.5K 361K ... 428K 0 ( 0%) 0%
branch_misses 4.63M ± 69.8K 4.52M ... 4.73M 0 ( 0%) 0%
Benchmark 2 (24 runs): ./branch-fast fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 213ms ± 1.87ms 210ms ... 220ms 1 ( 4%) ⚡- 26.8% ± 0.5%
peak_rss 60.2MB ± 599KB 59.3MB ... 61.5MB 2 ( 8%) + 0.0% ± 0.8%
cpu_cycles 960M ± 7.24M 947M ... 982M 5 (21%) ⚡- 27.9% ± 0.4%
instructions 2.95G ± 294 2.95G ... 2.95G 0 ( 0%) ⚡- 28.9% ± 0.0%
cache_references 9.80M ± 232K 9.46M ... 10.4M 3 (13%) ⚡- 10.1% ± 2.9%
cache_misses 356K ± 28.7K 292K ... 448K 2 ( 8%) ⚡- 9.7% ± 4.2%
branch_misses 3.78M ± 56.0K 3.67M ... 3.87M 0 ( 0%) ⚡- 18.3% ± 0.8%
```
### ReleaseSafe
```
Benchmark 1 (6 runs): ./master-safe fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 896ms ± 131ms 839ms ... 1.16s 0 ( 0%) 0%
peak_rss 85.1MB ± 669KB 84.2MB ... 86.0MB 0 ( 0%) 0%
cpu_cycles 3.83G ± 8.13M 3.82G ... 3.84G 0 ( 0%) 0%
instructions 13.0G ± 472 13.0G ... 13.0G 0 ( 0%) 0%
cache_references 86.4M ± 309K 85.8M ... 86.7M 1 (17%) 0%
cache_misses 4.31M ± 333K 4.12M ... 4.99M 0 ( 0%) 0%
branch_misses 15.8M ± 260K 15.5M ... 16.3M 0 ( 0%) 0%
Benchmark 2 (7 runs): ./branch-safe fmt --check lib
measurement mean ± σ min ... max outliers delta
wall_time 766ms ± 2.12ms 763ms ... 769ms 0 ( 0%) ⚡- 14.5% ± 12.0%
peak_rss 48.8MB ± 623KB 48.1MB ... 49.7MB 0 ( 0%) ⚡- 42.7% ± 0.9%
cpu_cycles 3.19G ± 8.17M 3.18G ... 3.21G 0 ( 0%) ⚡- 16.6% ± 0.3%
instructions 10.3G ± 750 10.3G ... 10.3G 0 ( 0%) ⚡- 20.9% ± 0.0%
cache_references 78.9M ± 404K 78.2M ... 79.2M 0 ( 0%) ⚡- 8.7% ± 0.5%
cache_misses 5.41M ± 51.7K 5.35M ... 5.47M 0 ( 0%) 💩+ 25.5% ± 6.5%
branch_misses 15.6M ± 102K 15.5M ... 15.8M 0 ( 0%) - 1.3% ± 1.5%
```
```
Benchmark 1 (12 runs): ./master-safe fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 432ms ± 1.07ms 430ms ... 433ms 0 ( 0%) 0%
peak_rss 115MB ± 480KB 115MB ... 116MB 1 ( 8%) 0%
cpu_cycles 1.95G ± 3.63M 1.95G ... 1.96G 0 ( 0%) 0%
instructions 6.95G ± 237 6.95G ... 6.95G 3 (25%) 0%
cache_references 25.1M ± 786K 24.3M ... 27.1M 1 ( 8%) 0%
cache_misses 558K ± 17.4K 524K ... 587K 0 ( 0%) 0%
branch_misses 5.11M ± 84.6K 4.98M ... 5.22M 0 ( 0%) 0%
Benchmark 2 (17 runs): ./branch-safe fmt --check src/codegen/x86_64/CodeGen.zig
measurement mean ± σ min ... max outliers delta
wall_time 302ms ± 1.38ms 299ms ... 304ms 0 ( 0%) ⚡- 30.1% ± 0.2%
peak_rss 80.9MB ± 577KB 79.8MB ... 81.8MB 0 ( 0%) ⚡- 29.6% ± 0.4%
cpu_cycles 1.37G ± 6.22M 1.35G ... 1.38G 0 ( 0%) ⚡- 29.8% ± 0.2%
instructions 4.75G ± 386 4.75G ... 4.75G 0 ( 0%) ⚡- 31.6% ± 0.0%
cache_references 18.5M ± 308K 18.2M ... 19.4M 0 ( 0%) ⚡- 26.1% ± 1.7%
cache_misses 459K ± 16.7K 431K ... 494K 0 ( 0%) ⚡- 17.6% ± 2.4%
branch_misses 4.01M ± 114K 3.87M ... 4.21M 0 ( 0%) ⚡- 21.4% ± 1.6%
```