Bitmap: Fix thunk explosion
authorBen Gamari <bgamari.foss@gmail.com>
Thu, 9 Jul 2015 00:08:01 +0000 (02:08 +0200)
committerBen Gamari <ben@smart-cactus.org>
Thu, 9 Jul 2015 00:08:01 +0000 (02:08 +0200)
commitb29633f5cf310824f3e34716e9261162ced779d3
tree5bfb753fb27c55a52c4cdc1303dee150015278a3
parent4f9d6008c04b71fc9449b3dc10861f757539ed0f
Bitmap: Fix thunk explosion

Previously we would build up another `map (-N)` thunk
for every word in the bitmap. Now we strictly accumulate the position
and carry out a single ``map (`subtract` accum)``.

`Bitmap.intsToBitmap` showed up in the profile while compiling a
testcase of #7450 (namely a program containing a record type with large
number of fields which derived `Read`). The culprit was
`CmmBuildInfoTables.procpointSRT.bitmap`. On the testcase (with 4096
fields), the profile previously looked like,

```
total time  =      307.94 secs   (307943 ticks @ 1000 us, 1
processor)
total alloc = 336,797,868,056 bytes  (excludes profiling
overheads)

COST CENTRE              MODULE              %time %alloc

lintAnnots               CoreLint             17.2   25.8
procpointSRT.bitmap      CmmBuildInfoTables   11.3   25.2
FloatOutwards            SimplCore             7.5    1.6
flatten.lookup           CmmBuildInfoTables    4.0    3.9
...
```

After this fix it looks like,
```
total time  =      256.88 secs   (256876 ticks @ 1000 us, 1
processor)
total alloc = 255,033,667,448 bytes  (excludes profiling
overheads)

COST CENTRE              MODULE              %time %alloc

lintAnnots               CoreLint             20.3   34.1
FloatOutwards            SimplCore             9.1    2.1
flatten.lookup           CmmBuildInfoTables    4.8    5.2
pprNativeCode            AsmCodeGen            3.7    4.3
simplLetUnfolding        Simplify              3.6    2.2
StgCmm                   HscMain               3.6    2.1
```

Signed-off-by: Ben Gamari <ben@smart-cactus.org>
Test Plan: Validate

Reviewers: austin, simonpj

Reviewed By: simonpj

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1041

GHC Trac Issues: #7450
compiler/cmm/Bitmap.hs