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)
Showing
- compiler/GHC/ByteCode/Asm.hs 460 additions, 230 deletionscompiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Instr.hs 5 additions, 0 deletionscompiler/GHC/ByteCode/Instr.hs
- compiler/GHC/ByteCode/Types.hs 1 addition, 1 deletioncompiler/GHC/ByteCode/Types.hs
- compiler/GHC/Data/FlatBag.hs 8 additions, 5 deletionscompiler/GHC/Data/FlatBag.hs
- compiler/GHC/Data/SmallArray.hs 21 additions, 0 deletionscompiler/GHC/Data/SmallArray.hs
- testsuite/tests/perf/should_run/ByteCodeAsm.hs 66 additions, 0 deletionstestsuite/tests/perf/should_run/ByteCodeAsm.hs
- testsuite/tests/perf/should_run/all.T 8 additions, 0 deletionstestsuite/tests/perf/should_run/all.T
Loading
Please register or sign in to comment