perf: avoid syncing directories when they already existed#107
Merged
guseggert merged 1 commit intoipfs:masterfrom May 24, 2022
Merged
perf: avoid syncing directories when they already existed#107guseggert merged 1 commit intoipfs:masterfrom
guseggert merged 1 commit intoipfs:masterfrom
Conversation
When doing a Put, the containing directory is always created. If it already exist, no error bubbles up from makeDirNoSync and later this directy is always synched on disk in makeDir. This generate FS operations which are almost always unnecessary as the supporting folders are quickly all created.
Contributor
Author
|
I tried to benchmark both version but the results vary widely from one run to another, even when using flags like My benchmark code was: func BenchmarkPut(b *testing.B) {
temp, cleanup := tempdir(b)
defer cleanup()
// defer checkTemp(b, temp)
fs, err := flatfs.CreateOrOpen(temp, flatfs.NextToLast(2), false)
if err != nil {
b.Fatalf("New fail: %v\n", err)
}
defer fs.Close()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
err = fs.Put(bg, datastore.NewKey("QUUX"), []byte("foobar"))
if err != nil {
b.Fatalf("Put fail: %v\n", err)
}
}
} |
Contributor
|
Are you saying that there's no measurable difference in performance? If that's the case, I'd prefer to keep things consistent / make less assumptions, makes the code easier to maintain. |
Contributor
Author
|
I did another benchmarking on NFS: 13% faster, 12% less allocation (bytes), 9% less allocation (count) ... but as you can see, the benchmark varies. |
guseggert
approved these changes
May 24, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When doing a Put, the containing directory is always created. If it already exist,
no error bubbles up from
makeDirNoSyncand later this directly is always synced on diskin
makeDir.This generate FS operations which are almost always unnecessary as the supporting folders
are quickly all created.