diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2019-05-27 20:52:02 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-09-09 05:42:33 -0400 |
commit | 4cf91d1abc0232ef6b85f44dfb2bb025ab0c70b0 (patch) | |
tree | 78370707e68114af6a1e75c2a0b4fd2da65e98fb /ghc | |
parent | d0b45ac6984f245bce9de7ffcc7dad4a0046d344 (diff) | |
download | haskell-4cf91d1abc0232ef6b85f44dfb2bb025ab0c70b0.tar.gz |
Use lazyness for FastString's z-encoding memoization
Having an IORef in FastString to memoize the z-encoded version is
unecessary because there is this amazing thing Haskell can do natively,
it's called "lazyness" :)
We simply remove the UNPACK and strictness annotations from the constructor
field corresponding to the z-encoding, making it lazy, and store the
(pure) z-encoded string there.
The only complication here is 'hasZEncoding' which allows cheking if a
z-encoding was computed for a given string. Since this is only used for
compiler performance statistics though it's not actually necessary to have
the current per-string granularity.
Instead I add a global IORef counter to the FastStringTable and use
unsafePerformIO to increment the counter whenever a lazy z-encoding is
forced.
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/Main.hs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/ghc/Main.hs b/ghc/Main.hs index 614b45f277..ea320be40f 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -815,11 +815,11 @@ dumpFinalStats dflags = dumpFastStringStats :: DynFlags -> IO () dumpFastStringStats dflags = do segments <- getFastStringTable + hasZ <- getFastStringZEncCounter let buckets = concat segments bucketsPerSegment = map length segments entriesPerBucket = map length buckets entries = sum entriesPerBucket - hasZ = sum $ map (length . filter hasZEncoding) buckets msg = text "FastString stats:" $$ nest 4 (vcat [ text "segments: " <+> int (length segments) , text "buckets: " <+> int (sum bucketsPerSegment) |