Skip to content

Avoid unnecessary allocations due to tracing utilies

Ben Gamari requested to merge wip/lower-tc-tracing-cost into master

While looking at a ticky profile of GHC compiling Cabal's Distribution.SPDX.LicenseId module I noticed that we were allocating hundreds of millions of SDocs during typechecking. For instance, in GHC.Tc.Utils.Zonk.commitFlexi (called from GHC.Tc.Utils.Zonk.zonkTyVarOcc) we allocated 24 million documents of each of the "Defaulting flexi tyvar to ..." documents. This is simply awful. Moreover, it tends to be a theme in our tracing utilities.

Avoid this by ensuring that the dump flag check is inlined into the call site, ensuring that the tracing document needn't be allocated unless it's actually needed.

Fixes #18168 (closed).

Edited by Ben Gamari

Merge request reports