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

Fix NSData initWithContentsOfURL: caching data of file URLs #309

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

triplef
Copy link
Member

@triplef triplef commented Jul 26, 2023

Initializing NSData with a file URL was using -[NSURL resourceDataUsingCache:] to load the file, which as a side effect caused the file data to be cached in memory. This is probably not desired behavior and caused very large memory growths in our application, and doesn’t match the behavior on Apple platforms.

@triplef triplef requested a review from rfm as a code owner July 26, 2023 19:44
@triplef
Copy link
Member Author

triplef commented Jul 26, 2023

Thinking about this some more I'm wondering if we should generally disable caching of file URLs in the NSURL resource loading system?

That being said I think this change still makes sense to reduce overhead when loading file URLs.

Copy link
Contributor

@rfm rfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks OK. Generally it makes sense to implement Apple's behavior.
With regards to the caching of file URLs more generally, I think you are probably right that we shouldn't do it. Generally a modern O/S will cache disk reads, so re-reading the same file is likely to be quite quick, and if a specialised app really needs to cache information in its own memory to avoid system call overheads, it's probably going to want to control that cache itself (I know that when optimising I want to control my own cache behaviors).

@triplef triplef merged commit 0aaa530 into master Aug 1, 2023
9 checks passed
@triplef triplef deleted the fix-nsdata-file-cache branch August 1, 2023 11:27
@triplef
Copy link
Member Author

triplef commented Aug 1, 2023

Thanks. Do you know where the NSURL caching behavior is controlled / what we’d need to change to disable file caching?

@rfm
Copy link
Contributor

rfm commented Aug 1, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants