[Git][ghc/ghc][wip/mpickering-hannes] Never UNPACK `FastMutInt` for counting z-encoded `FastString`s

Hannes Siebenhandl (@fendor) gitlab at gitlab.haskell.org
Wed Mar 27 14:03:47 UTC 2024



Hannes Siebenhandl pushed to branch wip/mpickering-hannes at Glasgow Haskell Compiler / GHC


Commits:
de963147 by Fendor at 2024-03-27T15:02:52+01:00
Never UNPACK `FastMutInt` for counting z-encoded `FastString`s

In `FastStringTable`, we count the number of z-encoded FastStrings
that exist in GHC.
We used to UNPACK the counters to not waste memory, but live retainer
analysis showed that we allocate a lot of `FastMutInt`s, retained by
`mkFastZString`.

We lazily compute the `FastZString`, only incrementing the counter when the `FastZString` is
forced.
The function `mkFastStringWith` calls `mkZFastString` and boxes the
`FastMutInt`, leading to the following core:

    mkFastStringWith
      = \ mk_fs _  ->
             = case stringTable of
                { FastStringTable _ n_zencs segments# _ ->
                    ...
                         case ((mk_fs (I# ...) (FastMutInt n_zencs))
                            `cast` <Co:2> :: ...)
                            ...

Marking this field as `NOUNPACK` avoids this reboxing, eliminating the
allocation of a fresh `FastMutInt` on every `FastString` allocation.

- - - - -


1 changed file:

- compiler/GHC/Data/FastString.hs


Changes:

=====================================
compiler/GHC/Data/FastString.hs
=====================================
@@ -308,7 +308,7 @@ See Note [Updating the FastString table] on how it's updated.
 -}
 data FastStringTable = FastStringTable
   {-# UNPACK #-} !FastMutInt -- the unique ID counter shared with all buckets
-  {-# UNPACK #-} !FastMutInt -- number of computed z-encodings for all buckets
+  {-# NOUNPACK #-} !FastMutInt -- number of computed z-encodings for all buckets
   (Array# (IORef FastStringTableSegment)) -- concurrent segments
 
 data FastStringTableSegment = FastStringTableSegment



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/de963147f76ee311e0a888f212e347f7c9bf8713

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/de963147f76ee311e0a888f212e347f7c9bf8713
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240327/c5f764ae/attachment.html>


More information about the ghc-commits mailing list