Skip to content

Draft: Wip/doyougnu/perf/use os path fingerprint dyn flags

build cabal-install with a profiled and ticky'd build and you get this:

COST CENTRE                   MODULE                          SRC                                                                %time %alloc

$wmkFastStringWith            GHC.Data.FastString             <no location info>                                                  13.3    3.7
++                            GHC.Internal.Base               libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4             3.6    4.4
$sgo15_$s$sgo1                GHC.Unit.Module.Env             <no location info>                                                   3.4    1.7
$wpoly_go2                    GHC.Unit.Module.Env             <no location info>                                                   2.7    0.3
mkFastStringBytes1            GHC.Data.FastString             <no location info>                                                   2.7    1.1
bracket1                      GHC.Internal.IO                 <no location info>                                                   2.5    6.9

track where ++ is coming from and you get this:

   7372:                                                                          ++                                                      GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           20766      117046    0.9    0.7     0.9    0.7
   7377:                                                                           ++                                                     GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           20733        6261    0.0    0.0     0.0    0.0
   7521:                                                                   ++                                                             GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19807         554    0.0    0.0     0.0    0.0
   7630:                                                                      ++                                                          GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19684       82824    0.5    0.9     0.5    0.9
   7634:                                                                       ++                                                         GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19661       82314    0.4    0.8     0.4    0.8
   7646:                                                                          ++_$s++                                                 GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19676        6528    0.0    0.0     0.6    0.7
   7647:                                                                           ++                                                     GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19687       64770    0.6    0.7     0.6    0.7
   7653:                                                                         ++_$s++                                                  GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19681         510    0.0    0.0     0.0    0.0

left column is line numbers in the profile, the top hit ++ are at 7372, 7630 and 7634 which correspond to:

7372:

                                                                         go31                                                     GHC.IfaceToCore                                              <no location info>                                                                                 20765       56317    0.1    0.3     1.0    1.0
                                                                          ++                                                      GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           20766      117046    0.9    0.7     0.9    0.7


notice that its in GHC.IfaceToCore. There are only two go functions in that module and honestly IfLclEnv could be paired down in size quite a bit.

7630 and 7634:

                                                                   fingerprintDynFlags1                                           GHC.Iface.Recomp.Flags                                       <no location info>                                                                                 19593          34    0.0    0.0     6.3    5.9
                                                                    map                                                           GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1891:1-3                                           19627       10413    0.1    0.2     5.2    5.9
...
                                                                     normalise                                                    System.FilePath.Posix                                        libraries/filepath/System/FilePath/Internal.hs:1029:1-9                                            19650         510    0.4    0.0     3.9    5.1
                                                                      ++                                                          GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19684       82824    0.5    0.9     0.5    0.9
                                                                      splitDirectories_f                                          System.FilePath.Posix                                        libraries/filepath/System/FilePath/Internal.hs:878:9                                               19657        8568    0.2    0.3     2.1    3.3
                                                                       $wbreak                                                    GHC.Internal.List                                            libraries/ghc-internal/src/GHC/Internal/List.hs:1329:1-5                                           19659       82314    1.4    1.9     1.4    1.9
                                                                        isPathSeparator                                           System.FilePath.Posix                                        libraries/filepath/System/FilePath/Internal.hs:204:1-15                                            19660       81804    0.0    0.0     0.0    0.0
                                                                       ++                                                         GHC.Internal.Base                                            libraries/ghc-internal/src/GHC/Internal/Base.hs:1984:1-4                                           19661       82314    0.4    0.8     0.4    0.8

These come the use of normalise in System.FilePath.Posix in fingerprintDynFlags, where is that being called in GHC? Well right here friend:

-- | This module manages storing the various GHC option flags in a modules
-- interface file as part of the recompilation checking infrastructure.
module GHC.Iface.Recomp.Flags (
        fingerprintDynFlags
      , fingerprintOptFlags
      , fingerprintHpcFlags
    ) where
...

import System.FilePath (normalise)
...

This MR is a peek into the work required to replace FilePath with OsPath and to see any perf changes

Edited by jeffrey young

Merge request reports