hledger/hledger-lib/Hledger
Simon Michael f78dc639a5 fix a slowdown with report rendering in 1.19.1 (#1350)
stripAnsi is called many times during rendering (by strWidth), so
should be fast. It was originally a regex replacement, and more
recently a custom parser. The parser was slower, particularly the one
in 1.19.1. See #1350, and this rough test:

time118ish = timeIt $ print $ length $ concat $ map (fromRight undefined . regexReplace (toRegex' "\ESC\\[([0-9]+;)*([0-9]+)?[ABCDHJKfmsu]") "") testdata
time119    = timeparser (many (takeWhile1P Nothing (/='\ESC') <|> "" <$ ansi))
time1191   = timeparser (many ("" <$ try ansi <|> pure <$> anySingle))
timeparser p = timeIt $ print $ length $ concat $ map (concat . fromJust . parseMaybe p) testdata
testdata = concat $ replicate 10000
    [ "2008-01-01 income               assets🏦checking            $1            $1"
    , "2008-06-01 gift                 assets🏦checking            $1            $2"
    , "2008-06-02 save                 assets🏦saving              $1            $3"
    , "                                assets🏦checking  ..m$-1\ESC[m\ESC[m            $2"
    , "2008-06-03 eat & shop           assets:cash           ..m$-2\ESC[m\ESC[m             0"
    , "2008-12-31 pay off              assets🏦checking  ..m$-1\ESC[m\ESC[m  ..m$-1\ESC[m\ESC[m"
    ]

ghci> time118ish
4560000
CPU time:   0.17s
ghci> time119
4560000
CPU time:   0.91s
ghci> time1191
4560000
CPU time:   2.76s

Possibly a more careful parser could beat regexReplace. Note the
latter does memoisation, which could be faster and/or could also use
more resident memory in some situations.

Ideally we would calculate all widths before adding ANSI colour codes,
so we wouldn't have to wastefully strip them.
2020-09-10 18:07:40 -07:00
..
Data ;partial comment cleanups 2020-09-03 09:52:00 -07:00
Read lib,cli,ui: Change to consistent naming scheme for Hledger.Utils.Regex. 2020-09-01 11:36:34 +10:00
Reports Replace our stringly Regex with a safer compiled Regexp type 2020-09-01 10:33:33 -07:00
Utils fix a slowdown with report rendering in 1.19.1 (#1350) 2020-09-10 18:07:40 -07:00
Data.hs move JSON instances from hledger-web to hledger-lib 2019-12-16 17:17:00 -08:00
Query.hs lib,cli,ui: Change to consistent naming scheme for Hledger.Utils.Regex. 2020-09-01 11:36:34 +10:00
Read.hs lib,cli: Replace parsedate and mkdatespan with direct applications of fromGregorian, transaction now takes Day instead of a date string. 2020-08-29 15:08:28 -07:00
Reports.hs lib,cli,ui: Remove redundant Typeable and Data instances. 2020-08-31 15:41:30 +10:00
Utils.hs ;review, tag all error calls with an easier to find PARTIAL: comment (#1312) 2020-08-05 16:08:33 -07:00