Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14010] FileManager.default.attributesOfItem extremely slow #4381

Open
swift-ci opened this issue Dec 31, 2020 · 2 comments
Open

[SR-14010] FileManager.default.attributesOfItem extremely slow #4381

swift-ci opened this issue Dec 31, 2020 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14010
Radar rdar://problem/72864729
Original Reporter nathan.fiscaletti (JIRA User)
Type Bug
Environment

macOS 11.0.1

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: b51fca1a0395e45f27d98eafdf1508b4

Issue Description:

It seems that the `FileManager.default.attributesOfItem` function takes upwards of 10 seconds to run at times.

Example

NSLog("checking if it exists")
if FileManager.default.fileExists(atPath: ServerCache.path) {
    let now = Date()
    NSLog("reading the modification date")
    let modDate = try! FileManager.default.attributesOfItem(atPath: ServerCache.path)[.modificationDate] as! Date
    
    if modDate.distance(to: now) < ServerCache.expiry {
        NSLog("reading from the file")
        let cacheData = try! String.init(contentsOfFile: ServerCache.path, encoding: .utf8)
        NSLog("finished reading from file")
    }
}

The above code results in the following log messages (note the timestamps)

2020-12-31 10:00:08.238567-0600 Vrazo[6660:1806095] checking if it exists
2020-12-31 10:00:08.414608-0600 Vrazo[6660:1806095] reading the modification date
2020-12-31 10:00:17.142044-0600 Vrazo[6660:1806095] reading from the file
2020-12-31 10:00:17.287236-0600 Vrazo[6660:1806095] finished reading from file
@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Anthony Miller (JIRA)

I'm seeing this problem also in my unit tests. It's only happening on macOS on my local machine. Runs nice and quick on the iOS simulator and on my CI machine.

Also, its only happening for the first file that I read attributes from. If I read attributes of a second file, it is fast again.

Using macOS 11.4 and running XCTest on Xcode 12.5

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants