[Git][ghc/ghc][wip/romes/27401-2] perf: Share Module in Iface Symbol Table
Rodrigo Mesquita pushed to branch wip/romes/27401-2 at Glasgow Haskell Compiler / GHC Commits: c3b3affb by Rodrigo Mesquita at 2026-06-18T17:15:18+01:00 perf: Share Module in Iface Symbol Table This commit modifies the structure of the serialized `SymbolTable Name` to then re-use and share the `Module` (both on disk and in memory) across all `Name`s from the same module. The new structure looks like: <total name count> $modules.size for (mod, names) in $modules: $mod $names.size for table_ix, occ in $names $table_ix $occ i.e. we put the module just once, followed by all names in that module. When deserializing, we deserialize the module just once, and all the following `Name`s are constructed with a pointer to that same decoded `Module`. Fixes #27401 - - - - - 1 changed file: - utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs Changes: ===================================== utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs ===================================== @@ -50,7 +50,9 @@ import GHC.Iface.Type (IfaceType, putIfaceType) import GHC.Types.Name.Cache import GHC.Types.Unique import GHC.Types.Unique.FM +import GHC.Types.Name.Env import GHC.Unit.State +import GHC.Unit.Module.Env import GHC.Utils.Binary import Haddock.Types import Text.ParserCombinators.ReadP (readP_to_S) @@ -139,7 +141,7 @@ binaryInterfaceMagic = 0xD0Cface -- binaryInterfaceVersion :: Word16 #if MIN_VERSION_ghc(9,11,0) && !MIN_VERSION_ghc(10,2,0) -binaryInterfaceVersion = 46 +binaryInterfaceVersion = 47 binaryInterfaceVersionCompatibility :: [Word16] binaryInterfaceVersionCompatibility = [binaryInterfaceVersion] @@ -170,7 +172,7 @@ writeInterfaceFile filename iface = do -- Make some intial state symtab_next <- newFastMutInt 0 - symtab_map <- newIORef emptyUFM + symtab_map <- newIORef emptyModuleEnv let bin_symtab = BinSymbolTable { bin_symtab_next = symtab_next @@ -269,18 +271,31 @@ putName name = do symtab_map <- readIORef symtab_map_ref - case lookupUFM symtab_map name of - Just (off, _) -> put_ bh (fromIntegral off :: Word32) + let mod' = nameModule name + case lookupModuleEnv symtab_map mod' of + Just nm_env -> + case lookupDNameEnv nm_env name of + Just (off, _) -> put_ bh (fromIntegral off :: Word32) + Nothing -> do + off <- freshIndex + writeIORef symtab_map_ref $! + extendModuleEnv symtab_map mod' (extendDNameEnv nm_env name (off, name)) + put_ bh (fromIntegral off :: Word32) Nothing -> do - off <- readFastMutInt symtab_next - writeFastMutInt symtab_next (off + 1) + off <- freshIndex writeIORef symtab_map_ref $! - addToUFM symtab_map name (off, name) + extendModuleEnv symtab_map mod' (extendDNameEnv emptyDNameEnv name (off, name)) put_ bh (fromIntegral off :: Word32) + where + freshIndex :: IO Int + freshIndex = do + off <- readFastMutInt symtab_next + writeFastMutInt symtab_next (off + 1) + return off data BinSymbolTable = BinSymbolTable { bin_symtab_next :: !FastMutInt -- The next index to use - , bin_symtab_map :: !(IORef (UniqFM Name (Int, Name))) + , bin_symtab_map :: !(IORef (ModuleEnv (DNameEnv (Int, Name)))) -- indexed by Name } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c3b3affb0427149846a0e979e1d7511a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c3b3affb0427149846a0e979e1d7511a... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Rodrigo Mesquita (@alt-romes)