Inlining does not work between modules
Hi! I discovered today something that looks like a terrifying bug. I was discussing it on IRC and so far there is no explanation why it happens. Let's grab a test code from here: https://github.com/luna/dependent-state/tree/irc-testing (branch irc-testing).
If you download it and execute stack --stack-yaml stack-develop.yaml bench dependent-state:layered-state-benchmark
benchmarks from test/bench/Main.hs
will be executed. Everything is compiled with -O2
etc (see stack-develop.yaml for details).
And now (everything regarding file Control/Monad/State/Layered.hs
):
- If you change lines
94-111
to use pointfree instead of normal arg, you get 40x slowdown - If you then uncomment lines
80-81
, everything is fast again.
The problem is that lines 80-81
are:
(.) :: (b -> c) -> (a -> b) -> a -> c
(.) f g = \x -> f (g x) ; {-# INLINE (.) #-}
It seems that this function is inlined ONLY if is defined in this module. If we use the one from base OR if we move this function to separate module, we can observe the slowdown.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | high |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |