Performance optimizations for data reading/writing #942
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've determined a few bottlenecks in the data reading/writing path that this PR addresses:
FileManager.removeItem(atPath:)
sincermdir
is noticeably faster thanremovefile
for known empty directories (the Linux implementation of removeItem(atPath:) already does this, so we can consider that for a future FM improvement for Darwin)AnyHashable
boxes and appending to the dictionaryCocoaError
, the compiler emits immediate calls to bridge it to anNSError
so this proved to be unnecessaryNSError
on Darwin to avoid a lot of bridging overhead (bridgingNSString
error key constants toString
to set in the dictionary just to bridge the dictionary back to ObjC, etc.) while maintaining the current status quo (where bridging isn't relevant) on non-Darwin.I updated our benchmarks to be a bit more accurate and to try to test some of these things. I was unable to get a benchmark/profile to accurately show me results for issue 1, but for issue 2 the read-nonexistentFile improved by 33% (compared to
main
) with the error creation reorganization and improved by 77% with the full solution as proposed by creating the error in ObjC to avoid double-bridging costs (compared tomain
)