Optimised git-annex branch log file timestamp parsing. 10% speedup
authorJoey Hess <joeyh@joeyh.name>
Thu, 29 Sep 2016 18:04:53 +0000 (14:04 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 29 Sep 2016 18:04:53 +0000 (14:04 -0400)
This sped up git annex find --not --in web from 6.64s to 5.69s.
The optimised parser is probably more like 50% faster than the general one
it replaced.

CHANGELOG
Logs/TimeStamp.hs

index 71f53793aac5801132ec8389d1616bee81508794..e94c1b0b30f703f0f1d8815c359c35ed812558d3 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ git-annex (6.20160924) UNRELEASED; urgency=medium
   * Optimisations to git-annex branch query and setting, avoiding repeated
     copies of the environment. Speeds up commands like 
     "git-annex find --in remote" by over 50%.
+  * Optimised git-annex branch log file timestamp parsing.
 
  -- Joey Hess <id@joeyh.name>  Mon, 26 Sep 2016 16:46:19 -0400
 
index 0891f920b3232a7aa7a75a6c0b36a2e718aea2db..a07b6a66daf6ffd3fc72bcaa85c2f62d31362ddc 100644 (file)
@@ -1,6 +1,6 @@
 {- log timestamp parsing
  -
- - Copyright 2015 Joey Hess <id@joeyh.name>
+ - Copyright 2015-2016 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU GPL version 3 or higher.
  -}
@@ -9,22 +9,31 @@
 
 module Logs.TimeStamp where
 
+import Utility.PartialPrelude
+import Utility.Misc
+
 import Data.Time.Clock.POSIX
 import Data.Time
+import Data.Ratio
 #if ! MIN_VERSION_time(1,5,0)
 import System.Locale
 #endif
-import Control.Applicative
-import Prelude
 
 {- Parses how POSIXTime shows itself: "1431286201.113452s"
  - Also handles the format with no fractional seconds. -}
 parsePOSIXTime :: String -> Maybe POSIXTime
-#if MIN_VERSION_time(1,5,0)
-parsePOSIXTime s = utcTimeToPOSIXSeconds <$> parseTimeM True defaultTimeLocale "%s%Qs" s
-#else
-parsePOSIXTime s = utcTimeToPOSIXSeconds <$> parseTime defaultTimeLocale "%s%Qs" s
-#endif
+parsePOSIXTime s = do
+       let (sn, sd) = separate (== '.') s
+       n <- readi sn
+       if null sd 
+               then return (fromIntegral n)
+               else do
+                       d <- readi sd
+                       let r = d % (10 ^ (length sd - 1))
+                       return (fromIntegral n + fromRational r)
+  where
+       readi :: String -> Maybe Integer
+       readi = readish
 
 formatPOSIXTime :: String -> POSIXTime -> String
 formatPOSIXTime fmt t = formatTime defaultTimeLocale fmt (posixSecondsToUTCTime t)