New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up the Haskell implementation #16
Conversation
It also modifies isMunchausen to look more like the other implementations.
With this change the Haskell implementation is now only 29% slower than the Rust implementation: % hyperfine ./haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.7/haskell-0.1.0.0/x/haskell/opt/build/haskell/haskell ./rust/target/release/rust Benchmark jabbalaci#1: ./haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.7/haskell-0.1.0.0/x/haskell/opt/build/haskell/haskell Time (mean ± σ): 3.277 s ± 0.080 s [User: 3.241 s, System: 0.026 s] Range (min … max): 3.170 s … 3.403 s 10 runs Benchmark jabbalaci#2: ./rust/target/release/rust Time (mean ± σ): 2.543 s ± 0.073 s [User: 2.522 s, System: 0.017 s] Range (min … max): 2.443 s … 2.669 s 10 runs Summary './rust/target/release/rust' ran 1.29 ± 0.05 times faster than './haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.7/haskell-0.1.0.0/x/haskell/opt/build/haskell/haskell'
We know the indexing is always safe because the size of the cache is known. % hyperfine ./haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.7/haskell-0.1.0.0/x/haskell/opt/build/haskell/haskell ./rust/target/release/rust Benchmark jabbalaci#1: ./haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.7/haskell-0.1.0.0/x/haskell/opt/build/haskell/haskell Time (mean ± σ): 2.959 s ± 0.015 s [User: 2.929 s, System: 0.023 s] Range (min … max): 2.937 s … 2.976 s 10 runs Benchmark jabbalaci#2: ./rust/target/release/rust Time (mean ± σ): 2.466 s ± 0.019 s [User: 2.449 s, System: 0.014 s] Range (min … max): 2.440 s … 2.494 s 10 runs Summary './rust/target/release/rust' ran 1.20 ± 0.01 times faster than './haskell/dist-newstyle/build/x86_64-osx/ghc-8.10.7/haskell-0.1.0.0/x/haskell/opt/build/haskell/haskell'
The llc and opt commands from LLVM 9-12 need to be available. If they're not in $PATH, set OPT and/or LLC env variables: make OPT=$(brew --prefix llvm@12)/bin/opt LLC=$(brew --prefix llvm@12)/bin/llc
Thanks. Nice optimization! Please check the dir. |
I guess that's because you're probably not using GHC 8.10.7. If that change works for you, I think it's fine. |
Ah apparently you're using 8.10.5 according to the updated README. In that case we should update Line 13 in d4090d8
|
Found it. In the PATH, I had to put |
This PR speeds up the Haskell implementation significantly using the LLVM backend.
Yesterday I saw someone wondering why the Haskell implementation was significantly slower than the other implementations in this test, so I took a stab at optimizing it.
The key points are:
Here's the result on my MacBook Pro 16'':
System prerequisites are:
ghcup install ghc 8.10.7 && ghcup install cabal latest
As noted in the commit message, the Makefile expects that llc and opt are available in $PATH. If not please set OPT and LLC accordingly when running make.