Ticket #783 (new compile-time performance bug)

Opened 3 years ago

Last modified 2 months ago

performance problem compiling large file

Reported by: guest Assigned to:
Priority: normal Milestone: 6.10.2
Component: Compiler Version: 6.4.2
Severity: normal Keywords: performance
Cc: kyrab@mail.ru, kfrdbs@gmail.com Difficulty: Unknown
Test Case: Operating System: Unknown/Multiple
Architecture: Unknown/Multiple

Description (Last modified by simonmar)

Windows XP, GHC 6.4.2 binary package.

Will attach the relevant module.

...
Compiling Dist             ( ./Dist.hs, ./Dist.o )
ghc: internal error: update_fwd: unknown/strange object  0
    Please report this as a compiler bug.  See:
    http://www.haskell.org/ghc/reportabug

Attachments

Dist.hs (133.6 kB) - added by simonmar on 06/22/06 05:37:27.

Change History

06/04/06 05:01:45 changed by drtom@dodo.com.au

As well as triggering the internal error, I found it necessary to increase the heap size, and it took *AGES*. So, I guess it's two bugs - the internal error and the performance bug.

cheers, Tom

06/06/06 03:49:55 changed by simonmar

  • severity changed from major to normal.
  • summary changed from ghc internal error to performance problem compiling large file.
  • os changed from Windows to Multiple.
  • description changed.
  • architecture changed from x86 to Multiple.

I'm 99% certain the crash has been fixed; see #787. However I tried the attached file, and it loaded without error on my 6.4.2 installation here.

Changing the title to reflect the performance problem, this is definitely an issue.

06/22/06 05:37:27 changed by simonmar

  • attachment Dist.hs added.

01/23/07 08:58:48 changed by igloo

  • testcase changed.
  • milestone set to 6.8.

Still a problem in 6.6 and the HEAD.

05/07/07 03:32:39 changed by simonmar

  • priority changed from normal to high.

07/03/07 02:11:46 changed by guest

  • cc set to kyrab@mail.ru.

08/23/07 15:31:35 changed by guest

  • cc changed from kyrab@mail.ru to kyrab@mail.ru, kfrdbs@gmail.com.

11/12/07 04:41:10 changed by simonmar

  • priority changed from high to normal.

11/12/07 08:30:10 changed by simonpj

  • milestone changed from 6.8 branch to 6.8.3.

See also #1875, #1136

12/14/07 07:17:26 changed by igloo

  • keywords set to performance.

01/07/08 02:44:56 changed by simonmar

  • type changed from bug to compile-time performance bug.

02/28/08 08:04:58 changed by igloo

With a slightly simpler variant of this:

module Foo where

foo :: Double -> Int
foo x | x == 1 = 1
foo x | x == 2 = 2
...
foo x | x == 500 = 500

compiling with

ghc -c large.hs -fforce-recomp +RTS -p -h

one problem is that we get something like

lit1 = ...
lit2 = ...
...

foo = case ... of
          False ->
              case ... of
                  False -> ...
                  True -> lit2
          True -> lit1

Each of the case expressions has an SRT for its alternatives. The outer one has all 500 lit's, the one inside 499, and so on, so we have quadratic space usage. The SRTs are SRTEntries cafs, where cafs is an IdSet (which is ultimately a UniqFM), so no sharing is possible.

In this particular case using -O "fixes" it as == etc get specialised and the lits disappear, but (a) this won't be the case in general and (b) I don't think you should need to use -O to get reasonable compiler space usage.

03/06/08 06:12:58 changed by simonpj

  • owner set to igloo.
  • type changed from compile-time performance bug to merge.

OK I have fixed the immediate problem.

Thu Mar  6 13:47:34 GMT 2008  simonpj@microsoft.com
  * Fix Trac #783: improve short-cutting literals in the type checker

Ian can you merge, and (somehow) add a test case to the test suite?

I'm not sure how to fully solve the quadratic behaviour in general. The reason that the lits were appearing in the SRT is because the dictionary for Num Float has a CAF in it. So, as Ian says, there really are N sub-SRTs for the various stages of evaluation. However things are now less bad than before:

  • Ian has made the SRTs use bitmaps:
    Wed Feb 27 06:45:05 PST 2008  Ian Lynagh <igloo@earth.li>
      * Add and use seqBitmap when constructing SRTs
    
  • The above patch from me makes the literal problem go away for Float and Double (common cases)

However, as Simon M says, I'm not sure why the N sub-SRTS don't all share a single table, and that should really kill off the quadratic behaviour in this case. That is the remaining bit that would be worth investigating. Maybe leave the ticket open for that.

Simon

03/17/08 13:05:56 changed by igloo

I've merged the patch.

Also, just to clarify, the patch Add and use seqBitmap when constructing SRTs is actually in a later stage of the compiler (although I did find that problem while looking at this bug). Going directly to a bitmap, rather than first making the SRTEntries, might be a way to fix this bug.

04/04/08 14:00:11 changed by igloo

  • type changed from merge to compile-time performance bug.

04/04/08 14:18:06 changed by igloo

  • owner deleted.

06/20/08 13:40:37 changed by igloo

  • milestone changed from 6.8.3 to 6.10.1.

09/30/08 08:45:05 changed by simonmar

  • architecture changed from Multiple to Unknown/Multiple.

09/30/08 08:54:43 changed by simonmar

  • os changed from Multiple to Unknown/Multiple.

10/04/08 04:51:17 changed by igloo

  • milestone changed from 6.10.1 to 6.10.2.