[GHC] #13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1)

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1)
-------------------------------------+-------------------------------------
Reporter: acowley | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Keywords: TypeFamilies | Operating System: Unknown/Multiple
Architecture: | Type of failure: Runtime
Unknown/Multiple | performance bug
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
I was recently made aware that [http://hackage.haskell.org/package/vinyl
vinyl]'s performance dramatically deteriorated with GHC 8.0.1 when
compared to GHC 7.x. Vinyl is an extensible records library that's been
around for about four years; the aspect of its design relevant here is the
basic HList-style indexed GADT. Care was taken in the past so that working
with, say, a `Storable` `Vector` of records would suffer no overhead from
`vinyl` when compared with standard records, and we have a benchmark suite
to spot check this.
In the move to GHC-8.0.1, it turns out that we do introduce overhead.
Inspecting the Core reveals that the benchmark inner loop includes a
`case` match on an `HEq_sc` value whose presence I would not expect, and
that is not present when compiling with GHC-7.10.3:
{{{
case HEq_sc
@ Nat
@ Nat
@ ('S 'Z)
@ (RIndex
'("normal", V3 Float)
'['("tex", V2 Float), '("normal", V3 Float)])
($s$fRElemar:S_$s$fRElemar:S_$cp1RElem
`cast` (N:~[0] <Nat>_N <'S 'Z>_N

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by acowley): * Attachment "Rec.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by acowley): * Attachment "Main.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by kosmikus): * cc: kosmikus (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by int-index): * cc: int-index (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: simonpj (added) Comment: Simon, this regression was caused by commit ff752a1a5eb69955c0e4fda8647f495409a2c384. Thoughts? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: simonpj (removed) * cc: goldfire (added) Comment: Ack, I was looking at the wrong commit previously. Apologies. It turns out the real culprit behind this regression is 1722fa106e10e63160bb2322e2ccb830fd5b9ab3 (by Richard). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): acowley, you mentioned that there was a "2x slowdown in the benchmark available in the `vinyl` repository". But I see [https://github.com/VinylRecords/Vinyl/blob/7f436533ba0680434053629df1f844fdb... two benchmarks]. Which benchmark suffered the slowdown? I'd like to verify the change in runtime speed before and after commit 1722fa106e10e63160bb2322e2ccb830fd5b9ab3. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by acowley): Thank you for taking a look, @RyanGIScott! It is the first benchmark there, with the unfortunate name `bench-builder-all`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): There does appear to be a difference in the `bench-builder-all` benchmark suite. The full results are available at https://gist.github.com/RyanGlScott/386da12bc71fd2fadae2362b257c41bc. The most noticeable differences come in the `vinyl` and `vinyl-plus` benchmarks. On GHC HEAD, I get: {{{ benchmarking vinyl time 106.9 µs (106.7 µs .. 107.0 µs) 1.000 R² (1.000 R² .. 1.000 R²) mean 106.7 µs (106.5 µs .. 106.9 µs) std dev 653.4 ns (506.9 ns .. 847.7 ns) benchmarking vinyl-lens time 83.98 µs (83.97 µs .. 84.00 µs) 1.000 R² (1.000 R² .. 1.000 R²) mean 83.97 µs (83.96 µs .. 83.98 µs) std dev 40.09 ns (33.48 ns .. 47.87 ns) }}} After reverting 1722fa106e10e63160bb2322e2ccb830fd5b9ab3, you get: {{{ benchmarking vinyl time 62.27 µs (62.25 µs .. 62.28 µs) 1.000 R² (1.000 R² .. 1.000 R²) mean 62.28 µs (62.26 µs .. 62.30 µs) std dev 58.65 ns (47.95 ns .. 71.78 ns) benchmarking vinyl-lens time 62.07 µs (62.01 µs .. 62.13 µs) 1.000 R² (1.000 R² .. 1.000 R²) mean 62.02 µs (61.98 µs .. 62.05 µs) std dev 122.0 ns (106.2 ns .. 144.8 ns) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by acowley): All the benchmarks in that suite should result in similar times. The idea is that it tests different representations and ways of accessing fields of records. The times you have there look somewhat suspicious to me. Here are my results, With GHC-8.0.1, {{{ benchmarking flat time 6.851 μs (6.658 μs .. 7.040 μs) 0.995 R² (0.993 R² .. 0.996 R²) mean 6.912 μs (6.757 μs .. 7.093 μs) std dev 577.7 ns (480.4 ns .. 799.9 ns) variance introduced by outliers: 82% (severely inflated) benchmarking vinyl time 7.081 μs (6.912 μs .. 7.240 μs) 0.995 R² (0.992 R² .. 0.997 R²) mean 7.116 μs (6.970 μs .. 7.308 μs) std dev 555.6 ns (437.9 ns .. 710.6 ns) variance introduced by outliers: 80% (severely inflated) benchmarking vinyl-lens time 17.55 μs (17.15 μs .. 18.01 μs) 0.995 R² (0.994 R² .. 0.997 R²) mean 17.84 μs (17.42 μs .. 18.47 μs) std dev 1.709 μs (1.244 μs .. 2.326 μs) variance introduced by outliers: 84% (severely inflated) benchmarking reasonable time 7.250 μs (7.069 μs .. 7.403 μs) 0.996 R² (0.994 R² .. 0.997 R²) mean 7.070 μs (6.931 μs .. 7.245 μs) std dev 502.5 ns (428.5 ns .. 586.9 ns) variance introduced by outliers: 77% (severely inflated) }}} While with GHC-7.10.3, I get, {{{ benchmarking flat time 7.107 μs (6.964 μs .. 7.265 μs) 0.995 R² (0.993 R² .. 0.997 R²) mean 7.241 μs (7.087 μs .. 7.431 μs) std dev 592.3 ns (498.5 ns .. 754.0 ns) variance introduced by outliers: 82% (severely inflated) benchmarking vinyl time 7.426 μs (7.295 μs .. 7.586 μs) 0.995 R² (0.993 R² .. 0.997 R²) mean 7.404 μs (7.230 μs .. 7.612 μs) std dev 648.7 ns (530.0 ns .. 800.1 ns) variance introduced by outliers: 83% (severely inflated) benchmarking vinyl-lens time 7.256 μs (7.097 μs .. 7.414 μs) 0.995 R² (0.992 R² .. 0.998 R²) mean 7.281 μs (7.119 μs .. 7.418 μs) std dev 507.4 ns (410.6 ns .. 651.8 ns) variance introduced by outliers: 76% (severely inflated) benchmarking reasonable time 7.231 μs (7.055 μs .. 7.385 μs) 0.995 R² (0.993 R² .. 0.997 R²) mean 7.221 μs (7.069 μs .. 7.388 μs) std dev 540.9 ns (453.3 ns .. 635.3 ns) variance introduced by outliers: 79% (severely inflated) }}} The `vinyl-lens` time going from 7.2 μs to 17.84 μs is representative of what I referred to as a 2x slowdown. This is on a 1.3 GHz Intel Core i5. It doesn't seem likely that you are running on that much of a slower CPU, but it is possible. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): This `HEq_sc` stuff is thoroughly bogus. Nice small test case thank you. I'll investigate. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1)
-------------------------------------+-------------------------------------
Reporter: acowley | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: TypeFamilies
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.3 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | simplCore/should_compile/T13025 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => merge * testcase: => simplCore/should_compile/T13025 * milestone: => 8.0.3 Comment: Fixed. Probably worth pushing the fix to 8.0.3. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.3 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | simplCore/should_compile/T13025 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I don't think your patch is quite right, Simon. Here is the main payload: {{{ pushCoArg :: Coercion -> CoreArg -> Maybe (CoreArg, Coercion) -- We have (fun |> co) arg, and we want to transform it to -- (fun arg) |> co -- This may fail, e.g. if (fun :: N) where N is a newtype -- C.f. simplCast in Simplify.hs pushCoArg co arg = case arg of Type ty | isForAllTy tyL -> ASSERT2( isForAllTy tyR, ppr co $$ ppr ty ) Just (Type ty, mkInstCo co (mkNomReflCo ty)) _ | isFunTy tyL , [co1, co2] <- decomposeCo 2 co -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) -- then co1 :: tyL1 ~ tyR1 -- co2 :: tyL2 ~ tyR2 -> ASSERT2( isFunTy tyR, ppr co $$ ppr arg ) Just (mkCast arg (mkSymCo co1), co2) _ -> Nothing where Pair tyL tyR = coercionKind co }}} This implements two of the push rules from every FC paper. But note that forall-types can now be heterogeneous. That is, `fun` and `fun |> co` might expect types of different kinds. Your patch does not take this possibility into account. I recommend this: {{{ case arg of Type ty | isForAllTy tyL -> ASSERT2( isForAllTy tyR, ppr co $$ ppr ty ) -- co :: (forall (a1 :: k1). ty1) ~ (forall (a2 :: k2). ty2) let co1 = mkSymCo (mkNthCo 0 co) -- co1 :: k2 ~ k1 ty' = ty `mkCastTy` co1 co2 = mkInstCo co (mkCoherenceLeftCo (mkNomReflCo ty) (mkSymCo co1)) -- co2 :: ty1[ty |> co1 / a1] ~ ty2[ty / a2] in Just (Type ty', co2) }}} Note that `NthCo` can extract an equality between the kinds of the types related by a coercion between forall-types. See the `NthCo` case in !CoreLint. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1)
-------------------------------------+-------------------------------------
Reporter: acowley | Owner:
Type: bug | Status: merge
Priority: normal | Milestone: 8.0.3
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: TypeFamilies
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Runtime | Test Case:
performance bug | simplCore/should_compile/T13025
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#13025: Type family reduction irregularity (change from 7.10.3 to 8.0.1) -------------------------------------+------------------------------------- Reporter: acowley | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.3 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | simplCore/should_compile/T13025 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): OK I fixed comment:13. Well spotted Richard! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13025#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC