aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-11-07 07:13:25 +0000
committerAndrew Kelley <andrew@ziglang.org>2023-11-08 23:55:53 -0700
commitd99bed1b10f85f2becca2a1c2587e1c2cb1968e6 (patch)
treee23b0ea094d2c4541c8dfa17d2a8681e892349ef /src/Compilation.zig
parenta1d688b86aeba7ab72ae12679ff04a7730931af3 (diff)
downloadzig-d99bed1b10f85f2becca2a1c2587e1c2cb1968e6.tar.gz
zig-d99bed1b10f85f2becca2a1c2587e1c2cb1968e6.zip
Sema: optimize runtime array_mul
There are two optimizations here, which work together to avoid a pathological case. The first optimization is that AstGen now records the result type of an array multiplication expression where possible. This type is not used according to the language specification, but instead as an optimization. In the expression '.{x} ** 1000', if we know that the result must be an array, then it is much more efficient to coerce the LHS to an array with length 1 before doing the multiplication. Otherwise, we end up with a 1000-element tuple which we must coerce to an array by individually extracting each field. Secondly, the previous logic would repeatedly extract element/field values from the LHS when initializing the result. This is unnecessary: each element must only be extracted once, and the result reused. These changes together give huge improvements to compiler performance on a pathological case: AIR instructions go from 65551 to 15, and total AIR bytes go from 1.86MiB to 264.57KiB. Codegen time spent on this function (in a debug compiler build) goes from minutes to essentially zero. Resolves: #17586
Diffstat (limited to 'src/Compilation.zig')
0 files changed, 0 insertions, 0 deletions