Skip to content

Improve sharing in `ModIface` after generation

Summary

Generation of ModIface can contain many duplicates, as demonstrated in #24540 (closed), especially when -fwrite-if-simplified-core was used, which embeds core expressions into the interface file.

This allows for much faster GHCi startups and also promises improved compilation performance during normal compilation (tbh, I haven't benchmarked this in particular, but it makes sense to me ;) )

To improve the sharing of ModIface, and thus reducing the memory footprint during compilation, we can use the serialisation mechanism of ModIface to achieve the same memory footprint improvement as in !12371 (closed), but for .hi file generation (again, assuming -fwrite-if-simplified-core is used).

We implemented this improvement and benchmarked it against GHC head (3fff0977). The benchmark was run on the agda codebase, using the following command (omitting the compilation options of agda):

$ ghci -fforce-recomp -fwrite-if-simplified-core +RTS -tprofile -i0.5

The results look as follows:

ghc compression level allocated peak_allocated all_seconds cpu_seconds hi file size
ghc head 1 65.6 GB 2218 MB 46.21 s 45.60 s 101.7 MB
ghc with sharing 1 66.0 GB 2259 MB 47.29 s 46.69 s 101.7 MB
ghc with sharing 2 66.6 GB 1984 MB 46.08 s 45.52 s 25.2 MB
ghc with sharing 3 66.6 GB 1534 MB 47.51 s 46.89 s 24.2 MB

The compression level is the flag -fwrite-if-compression which is introduced in !12371 (closed).

Edited by Hannes Siebenhandl
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information