Avoid UArray when indexing is not required
`UnlinkedBCO`'s can occur many times in the heap. Each `UnlinkedBCO` references two `UArray`'s but never indexes them. They are only needed to encode the elements into a `ByteArray#`. The three words for the lower bound, upper bound and number of elements are essentially unused, thus we replace `UArray` with a wrapper around `ByteArray#`. This saves us up to three words for each `UnlinkedBCO`. Further, to avoid re-allocating these words for `ResolvedBCO`, we repeat the procedure for `ResolvedBCO` and add custom `Binary` and `Show` instances. For example, agda's repl session has around 360_000 UnlinkedBCO's, so avoiding these three words is already saving us around 8MB residency.
Showing
- compiler/GHC/ByteCode/Asm.hs 3 additions, 3 deletionscompiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Linker.hs 6 additions, 3 deletionscompiler/GHC/ByteCode/Linker.hs
- compiler/GHC/ByteCode/Types.hs 6 additions, 3 deletionscompiler/GHC/ByteCode/Types.hs
- libraries/ghci/GHCi/CreateBCO.hs 4 additions, 8 deletionslibraries/ghci/GHCi/CreateBCO.hs
- libraries/ghci/GHCi/ResolvedBCO.hs 106 additions, 13 deletionslibraries/ghci/GHCi/ResolvedBCO.hs
- testsuite/tests/ghci/should_run/BinaryArray.hs 23 additions, 1 deletiontestsuite/tests/ghci/should_run/BinaryArray.hs
Please register or sign in to comment