Proposal: MapFile mechanism to avoid superfluous copy operation #21
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.
This PR proposes adding a method
FSCache.MapFilethat maps an existing on-disk file into aStandardFS-backedFSCachewithout performing an (expensive) copy operation. I wasn't able to figure out how to avoid the copy without adding new API surface (although it's entirely possible I've missed something obvious).Scenario
An example scenario is demonstrated in
TestMapFile. We've got aGettertype:An implementation of
Gettergets a reader for a URL, or a file, storing the contents in anFSCache. There's two implementations ofGetterprovided:StdGetteruses the previously available mechanism to copy contents into the cache using thewreturned byFSCache.Get.MapGetteruses the proposedFSCache.MapFilemechanism.The problem with
StdGettercan be seen here:In the real-world scenario that inspired this proposal, the file was large (several GB), and this copy operation became a performance chokepoint.
Proposal
Instead, we can do something like this:
In the very limited tests that I've run so far in my own project, this completely addresses the issue.
@djherbis: What are your thoughts on this mechanism? Am I missing some other existing way of avoiding the copy?