Skip to content

Commit

Permalink
perf: strictify Meta's ID field
Browse files Browse the repository at this point in the history
This one-character change massively reduces our memory usage (measured by
maximum residency) on some workloads.  When running the testsuite with
`--hedgehog-tests 0` (to get reproducible results) we see a (roughly)
15% drop in maximum residency (as measured by `+RTS -s`), and with the
following patch to run a much bigger version of `EvalFull.unit_8`, we
see a 97% drop, and the total memory in use drops from 1177MB to 58MB!
It also has a small beneficial effect on the amount of memory copied
during GC, and a negligible effect on both total memory allocated and
elapsed runtimes.

diff --git a/primer/test/Tests/EvalFull.hs b/primer/test/Tests/EvalFull.hs
index c98878049..9292b2870 100644
--- a/primer/test/Tests/EvalFull.hs
+++ b/primer/test/Tests/EvalFull.hs
@@ -209,13 +209,13 @@ unit_7 =

 unit_8 :: Assertion
 unit_8 =
-  let n = 10
+  let n = 100
       e = mapEven n
    in do
         evalFullTest (maxID e) builtinTypes (defMap e) 500 Syn (expr e) >>= \case
           Left (TimedOut _) -> pure ()
           x -> assertFailure $ show x
-        s <- evalFullTest (maxID e) builtinTypes (defMap e) 1000 Syn (expr e)
+        s <- evalFullTest (maxID e) builtinTypes (defMap e) 100000 Syn (expr e)
         s <~==> Right (expectedResult e)

 -- A worker/wrapper'd map

Signed-off-by: Ben Price <[email protected]>
  • Loading branch information
brprice committed Aug 10, 2023
1 parent e603e61 commit 305560d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion primer/src/Primer/Core/Meta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ newtype ID = ID {unID :: Int}
deriving newtype (ToJSONKey, FromJSONKey)
deriving anyclass (NFData)

data Meta a = Meta ID a (Maybe Value)
data Meta a = Meta !ID a (Maybe Value)
deriving stock (Generic, Eq, Ord, Show, Read, Data, Functor)
deriving (FromJSON, ToJSON) via PrimerJSON (Meta a)
deriving anyclass (NFData)
Expand Down

0 comments on commit 305560d

Please sign in to comment.