Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#10720 closed bug (invalid)

New GHC fails to specialize imported function

Reported by: wyager Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.10.2
Keywords: performance, inline, specialize Cc:
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I just installed the new Haskell platform for OS X.

It seems to have caused a major performance regression for a program I'm working on, making it well over 25x slower.

The culprit appears to be that the new GHC (7.10.2) fails to specialize an imported function. If I manually add a SPECIALIZE pragma, performance goes back to around what it used to be.

The code in question is located at https://github.com/wyager/HNet .

As it stands, the code takes about 30 seconds to run on my machine. With the previous haskell-platform, it only took about .9 seconds.

If I modify Operations.hs and uncomment the SPECIALIZE pragma, runtime goes down to about 1.1 seconds (still slower for some reason, but not awful).

To test, compile with -O2 (as the program makes heavy use of Data.Vector, which requires -fspec-constr for performance).

Change History (6)

comment:1 Changed 2 years ago by wyager

Also see #10721 for a potentially related issue.

comment:2 Changed 2 years ago by simonpj

I tried this. It's all behaving as advertised

  • You need an INLINEABLE pragma on (**).
  • If you add that, then (**) is getting specialised perfectly well; but it calls (*), which is not.
  • So you need an INLINEABLE pragma on (*) too.

Admittedly this isn't terribly clear. I'll add some new warnings to point out that this might be happening.

Meanwhile, you might just want to confirm that this is indeed ok for you.

Simon

comment:3 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In a426154/ghc:

Warn about missed specialisations for imports

This change was provoked by Trac #10720, where a missing
INLINEABLE pragma gave very poor performance.

The change is to warn when an imported function is not specialised
in a situation where the user expects it to be.

New flags
  -fwarn-missed-specialisations
  -fwarn-all-missed-specialisations

Documented in user manual.
See Note [Warning about missed specialisations]

comment:4 Changed 2 years ago by simonpj

Resolution: invalid
Status: newclosed

I'm going to close this as fixed, but please re-open if you disagree.

Thank you for a nice test case that made it easy for me to figure out what was happening.

Simon

comment:5 Changed 2 years ago by wyager

Thanks for the explanation. I am curious though; why is the specializing behavior different than it was in the previous Haskell-platform's GHC? Did it start to specialize less aggressively?

Will

comment:6 in reply to:  5 Changed 2 years ago by simonpj

Replying to wyager:

why is the specializing behavior different than it was in the previous Haskell-platform's GHC? Did it start to specialize less aggressively?

I'm afraid I don't know -- and I am reluctant to invest the time in finding out. But that shouldn't stand in the way of someone else looking.

Note: See TracTickets for help on using tickets.