clash-lang / clash-compiler

Haskell to VHDL/Verilog/SystemVerilog compiler
https://clash-lang.org/
Other
1.4k stars 147 forks source link

flattenLet applied in bottomup traversal #2599

Closed christiaanb closed 8 months ago

christiaanb commented 8 months ago

Ensures deeply nested let-bindings are flattened first so that let-expressions do not get inlined into argument positions in their unflattened form.

Has some minor performance effects.

Before:

benchmarking normalization of examples/Reducer.hs
time                 395.2 ms   (385.3 ms .. 410.2 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 401.3 ms   (396.8 ms .. 406.4 ms)
std dev              5.429 ms   (1.784 ms .. 7.434 ms)
variance introduced by outliers: 19% (moderately inflated)

benchmarking normalization of tests/shouldwork/Basic/AES.hs
time                 161.3 ms   (160.1 ms .. 162.5 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 164.9 ms   (163.1 ms .. 169.4 ms)
std dev              4.042 ms   (490.2 μs .. 5.968 ms)
variance introduced by outliers: 12% (moderately inflated)

After:

benchmarking normalization of examples/Reducer.hs
time                 447.0 ms   (439.0 ms .. 451.0 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 454.4 ms   (451.0 ms .. 460.9 ms)
std dev              6.411 ms   (13.17 μs .. 7.496 ms)
variance introduced by outliers: 19% (moderately inflated)

benchmarking normalization of tests/shouldwork/Basic/AES.hs
time                 182.2 ms   (180.8 ms .. 183.4 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 185.3 ms   (183.9 ms .. 188.1 ms)
std dev              2.666 ms   (490.4 μs .. 3.715 ms)
variance introduced by outliers: 14% (moderately inflated)

Fixes https://github.com/clash-lang/clash-compiler/issues/2598

DigitalBrains1 commented 8 months ago

About 13% slower isn't really a minor effect though?

christiaanb commented 8 months ago

Right, but the other benchmarks do not increase.