From 12603b2afb8131ba0b9050ae5d8b595d3884e606 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Thu, 19 Dec 2019 16:16:47 +0100 Subject: [PATCH] don't os.File.Sync() on mac CAS items os.File.Sync() was inneffective on mac in go prior to 1.12. In 1.12 onwards it is effective, but slow: https://github.com/golang/go/issues/26650 This change disables Sync for CAS uploads on mac, because we can (potentially) verify this later. Let's see if this helps performance on mac: #67 (while being less risky than #68). --- cache/disk/disk.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cache/disk/disk.go b/cache/disk/disk.go index 559a065fb..673d19969 100644 --- a/cache/disk/disk.go +++ b/cache/disk/disk.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "path/filepath" + "runtime" "sort" "sync" @@ -17,6 +18,8 @@ import ( "github.com/djherbis/atime" ) +const isMac = runtime.GOOS == "darwin" + // lruItem is the type of the values stored in SizedLRU to keep track of items. // It implements the SizedItem interface. type lruItem struct { @@ -236,8 +239,11 @@ func (c *diskCache) Put(kind cache.EntryKind, hash string, expectedSize int64, r } } - if err := f.Sync(); err != nil { - return err + shouldSync := !isMac || kind != cache.CAS + if shouldSync { + if err := f.Sync(); err != nil { + return err + } } if err := f.Close(); err != nil {