From 80ba594a6b44b9693eeaa27bf3bea225a57527ca Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 8 May 2026 00:04:31 +0100 Subject: Eliminate some thunks This saves ALL the memory; all files were previously kept in memory --- src/Config.hs | 2 +- src/Index.hs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Config.hs b/src/Config.hs index ffd4875..d6cf021 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -69,7 +69,7 @@ type family IfFull stage a where IfFull Full a = a -- | network, channelname -data Channel = Channel { chanNetwork :: Text, chanChannel :: Text } +data Channel = Channel { chanNetwork :: !Text, chanChannel :: !Text } deriving (Show, Eq, Ord) prettyChannel :: Channel -> Text diff --git a/src/Index.hs b/src/Index.hs index bdc3751..89a24e3 100644 --- a/src/Index.hs +++ b/src/Index.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE BangPatterns #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} @@ -95,14 +96,15 @@ initIndex basedir toimport = do Nothing -> error $ "Log file with unexpected file name: " ++ path -- atomicPrintS $ "Parsing " ++ path ++ " (" ++ show date ++ " -> " ++ show (dateToDay date) ++ ")" events <- parseLog <$> BS.readFile path - return (uncurry3 fromGregorian date, length events) + let !nevents = length events + return (uncurry3 fromGregorian date, nevents) let minday = minimum (map fst days) maxday = maximum (map fst days) ndays = fromIntegral @Integer @Int (diffDays maxday minday + 1) -- traceM $ nw ++ "/" ++ ch ++ ": days = " ++ show [(toFileName (dayToYMD d), i) | (d, i) <- days] let countScan = IGV.fromListN ndays (drop 1 $ scanl' (+) 0 (makeCounts [minday..maxday] days)) ntotal = sum (map snd days) - chanindex <- newIORef $ + chanindex <- newIORef $! ChanIndex { ciStartDay = minday , ciCountUntil = countScan , ciTotal = ntotal } -- cgit v1.3.1