Hi everyone,
recently I wanted to clean up a messy main.rs, which contained way too much code, by splitting parts into seperate modules. Basically, moving parts of main.rs into model/foo.rs, and model/mod.rs pub uses the structs, which main.rs then uses from model. The whole application has ~3300 lines of code, and I moved ~700 lines from main.rs into model/*.rs.
Other than moving the type definitions & impls, which required some struct fields to be made public, I didn't change any code.
Anyhow, this lead to a reproducible 10% runtime performance regression. I didn't expect that.
I'm on Rust 1.56.
Here's the benchmark output:
❯ hyperfine -w 10 --prepare "touch /home/kaspar/src/riot.laze/laze-project.yml" "laze -C /home/kaspar/src/riot.laze b -g -G"
Benchmark 1: laze -C /home/kaspar/src/riot.laze b -g -G
Time (mean ± σ): 1.098 s ± 0.033 s [User: 6.280 s, System: 0.285 s]
Range (min … max): 1.053 s … 1.144 s 10 runs
laze on refactored took 22s
❯ hyperfine -w 10 --prepare "touch /home/kaspar/src/riot.laze/laze-project.yml" "laze -C /home/kaspar/src/riot.laze b -g -G"
Benchmark 1: laze -C /home/kaspar/src/riot.laze b -g -G
Time (mean ± σ): 1.003 s ± 0.011 s [User: 5.697 s, System: 0.281 s]
Range (min … max): 0.982 s … 1.022 s 10 runs
Switching branches between those runs. Top run is from master branch, bottom one is from "refactored". These numbers are stable within 1%.
This is with "--release", lto="fat", compilation-units=1, incremental=false.
here is the application repository. This is the branch with the refactoring, and here is the used test data.
I obviously don't expect anyone to look at my code, I just don't know if I'm missing something obvious.
Are modules supposed to cause runtime overhead if used within a crate?
Thanks in advance, Kaspar