Skip to content
Snippets Groups Projects
Commit 8f6cc90c authored by Matthew Pickering's avatar Matthew Pickering Committed by Marge Bot
Browse files

perf: Speed up the bytecode assembler

This commit contains a number of optimisations to the bytecode
assembler. In programs which generate a large amount of bytecode, the
assembler is called a lot of times on many instructions.

1. Specialise the assembleI function for the two intepreters to avoid
having to materialise the intermediate free-monad like structure.
2. Directly compute the UArray and SmallArray needed rather than going
   via the intermediate SizedSeq
3. Use optimised monads
4. Define unrolled "any" and "mapM6" functions which can be inlined
   and avoid calling recursive functions.

The resulting generated code is much more direct.

Before:

./ByteCodeAsm /home/matt/ghc-profiling-light/_build/stage1/lib/ +RTS  -s
  48,923,125,664 bytes allocated in the heap
     678,221,152 bytes copied during GC
         395,648 bytes maximum residency (2 sample(s))
          50,040 bytes maximum slop
               6 MiB total memory in use (0 MiB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0     11731 colls,     0 par    0.419s   0.425s     0.0000s    0.0004s
  Gen  1         2 colls,     0 par    0.001s   0.001s     0.0007s    0.0012s

  INIT    time    0.000s  (  0.000s elapsed)
  MUT     time    6.466s  (  6.484s elapsed)
  GC      time    0.421s  (  0.426s elapsed)
  EXIT    time    0.000s  (  0.000s elapsed)
  Total   time    6.887s  (  6.910s elapsed)

After:

   1,518,321,200 bytes allocated in the heap
       4,299,552 bytes copied during GC
         322,288 bytes maximum residency (2 sample(s))
          50,280 bytes maximum slop
               6 MiB total memory in use (0 MiB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0       369 colls,     0 par    0.003s   0.003s     0.0000s    0.0002s
  Gen  1         2 colls,     0 par    0.001s   0.001s     0.0007s    0.0012s

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time    0.465s  (  0.466s elapsed)
  GC      time    0.004s  (  0.004s elapsed)
  EXIT    time    0.000s  (  0.000s elapsed)
  Total   time    0.470s  (  0.471s elapsed)
parent 7ca72844
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment