Skip to content

calibrateMtimeChangeDelay takes 25s to execute on Mac OS X with HFS+ system #4230

Open

Description

@gracjan
Prelude Distribution.Compat.Time Data.Time>
   do { t1 <- getCurrentTime;
        r <- calibrateMtimeChangeDelay;
        t2 <- getCurrentTime;
        print (t2 `diffUTCTime` t1);
        return r; }
24.609871s
(1006168,1000000)

HFS+ stores file modtime with 1 second resolution. Function is here:

calibrateMtimeChangeDelay :: IO (Int, Int)

Activity

  1. ezyang commented on Jan 12, 2017

    @ezyang
    Contributor

    CC @ndmitchell

    Probably what we should do is scale down number of calibration runs the longer the first run is.

  2. 23Skidoo commented on Jan 12, 2017

    @23Skidoo
    Member

    It's working correctly, this is a consequence of the algorithm and the HFS+ mtime delay you mention. We run it only once during setup, is that a big problem?

  3. 23Skidoo commented on Jan 13, 2017

    @23Skidoo
    Member

    I'm working on a patch.

  4. added a commit that references this issue on Jan 13, 2017
    6ea9180
  5. gracjan commented on Jan 13, 2017

    @gracjan
    Author

    Much better. Since it loos like you are trying to detect what is the FileModTime resolution for the underlying filesystem I would go for that number directly by probing writes:

    sampleMtime fileName = do
           writeFile fileName $ ""
           t0 <- getModTime fileName
           let spin = do
                 writeFile fileName $ ""
                 t1 <- getModTime fileName
                 if t0 < t1
                     then return (t1 `diffModTime` t0)
                     else spin
           spin
    

    Or by using setModificationTime directly (requires directory >= 1.2.3):

    *Distribution.Backpack System.Directory> 
        setModificationTime "prologue.txt" (read "2017-01-13 08:47:58.99999999999999 UTC") 
            >> getModificationTime "prologue.txt"
    2017-01-13 08:47:58 UTC
    
  6. gracjan commented on Jan 13, 2017

    @gracjan
    Author

    So with direct setting of modification time it would go like this:

    sampleMtime fileName = do
           writeFile fileName $ ""
           now <- getCurrentTime
           let todayAlmost1sAfterMidnight = now { utctDayTime = pred (1 :: DiffTime) }
           setModificationTime fileName todayAlmost1sAfterMidnight
           modTime <- getModificatonTime fileName
           return $ succ (diffUTCTime todayAlmost1sAfterMidnight modTime)
    

    Explanation: pred (1 :: DiffTime) gives one discrete time unit before 1s. We rely on setModificationTime flooring the time specification. Then succ recovers one discrete time unit giving a modification time resolution as stored by the file system.

    Note that the 'discrete time unit' is picosecond for UTCTime, but it does not really matter as succ . prec is identity.

    Note: DOS-FAT12/16 has 2s file mod time resolution and it can be supported by changing (1 :: DiffTime) to (2 :: DiffTime). I do not think we care.

  7. 23Skidoo commented on Jan 13, 2017

    @23Skidoo
    Member

    We need to support old versions of directory, so I think I'll leave it as is for now. I think that we can safely ignore FAT-16.

  8. added a commit that references this issue on Jan 13, 2017
    d62d7c1
  9. gracjan commented on Jan 13, 2017

    @gracjan
    Author

    Note that old version of calibrate managed to create the file 91k times during those 25s:

    In GHCi:

    *Distribution.Backpack Distribution.Compat.Time> calibrateMtimeChangeDelay 
    (1326524,1000000)
    

    Outside, 66664 is GHC pid:

    $ sudo opensnoop -p 66664 > snoop.txt
    $ grep probe snoop.txt | wc -l
       91207
    
  10. 23Skidoo commented on Jan 13, 2017

    @23Skidoo
    Member

    managed to create the file 91k times during those 25s

    You mean write to, not create.

  11. gracjan commented on Jan 13, 2017

    @gracjan
    Author

    I mean execute writeFile.

  12. ttuegel commented on Jan 14, 2017

    @ttuegel
    Member

    Could this be related to the macOS timeouts we're seeing on Travis?

  13. added 2 commits that reference this issue on Jan 16, 2017
    34fc13b
    976265c
  14. added a commit that references this issue on May 5, 2017
    9752f24
  15. self-assigned this
    on Oct 15, 2017
  16. removed their assignment
    on Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions