syncthing/lib/db/truncated.go

53 lines
1.3 KiB
Go
Raw Normal View History

// Copyright (C) 2014 The Syncthing Authors.
//
2015-03-07 20:36:35 +00:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
package db
Don't load block list in ...Truncated methods Speeds up and reduces allocations on those operations, at the price of having a manually tweaked XDR decoder for FileInfoTruncated. benchmark old ns/op new ns/op delta BenchmarkReplaceAll-8 1868198122 1880206886 +0.64% BenchmarkUpdateOneChanged-8 231852 172695 -25.51% BenchmarkUpdateOneUnchanged-8 230624 179341 -22.24% BenchmarkNeedHalf-8 104601744 109461427 +4.65% BenchmarkHave-8 29102480 34105026 +17.19% BenchmarkGlobal-8 150547687 172778045 +14.77% BenchmarkNeedHalfTruncated-8 102471355 76564986 -25.28% BenchmarkHaveTruncated-8 28758368 14277481 -50.35% BenchmarkGlobalTruncated-8 151192913 106070136 -29.84% benchmark old allocs new allocs delta BenchmarkReplaceAll-8 555577 557554 +0.36% BenchmarkUpdateOneChanged-8 1135 587 -48.28% BenchmarkUpdateOneUnchanged-8 1135 587 -48.28% BenchmarkNeedHalf-8 374780 374775 -0.00% BenchmarkHave-8 151992 152085 +0.06% BenchmarkGlobal-8 530033 530135 +0.02% BenchmarkNeedHalfTruncated-8 374699 22160 -94.09% BenchmarkHaveTruncated-8 151834 4904 -96.77% BenchmarkGlobalTruncated-8 530037 30536 -94.24% benchmark old bytes new bytes delta BenchmarkReplaceAll-8 1765116216 1765305376 +0.01% BenchmarkUpdateOneChanged-8 135085 93043 -31.12% BenchmarkUpdateOneUnchanged-8 134976 92928 -31.15% BenchmarkNeedHalf-8 44758752 44751791 -0.02% BenchmarkHave-8 11845052 11967172 +1.03% BenchmarkGlobal-8 80431136 80431065 -0.00% BenchmarkNeedHalfTruncated-8 46526459 18243543 -60.79% BenchmarkHaveTruncated-8 11348357 418998 -96.31% BenchmarkGlobalTruncated-8 80977672 43116991 -46.75%
2015-10-21 21:33:04 +00:00
import (
"github.com/calmh/xdr"
"github.com/syncthing/syncthing/lib/protocol"
)
type FileInfoTruncated struct {
2015-02-13 12:46:49 +00:00
protocol.FileInfo
}
Don't load block list in ...Truncated methods Speeds up and reduces allocations on those operations, at the price of having a manually tweaked XDR decoder for FileInfoTruncated. benchmark old ns/op new ns/op delta BenchmarkReplaceAll-8 1868198122 1880206886 +0.64% BenchmarkUpdateOneChanged-8 231852 172695 -25.51% BenchmarkUpdateOneUnchanged-8 230624 179341 -22.24% BenchmarkNeedHalf-8 104601744 109461427 +4.65% BenchmarkHave-8 29102480 34105026 +17.19% BenchmarkGlobal-8 150547687 172778045 +14.77% BenchmarkNeedHalfTruncated-8 102471355 76564986 -25.28% BenchmarkHaveTruncated-8 28758368 14277481 -50.35% BenchmarkGlobalTruncated-8 151192913 106070136 -29.84% benchmark old allocs new allocs delta BenchmarkReplaceAll-8 555577 557554 +0.36% BenchmarkUpdateOneChanged-8 1135 587 -48.28% BenchmarkUpdateOneUnchanged-8 1135 587 -48.28% BenchmarkNeedHalf-8 374780 374775 -0.00% BenchmarkHave-8 151992 152085 +0.06% BenchmarkGlobal-8 530033 530135 +0.02% BenchmarkNeedHalfTruncated-8 374699 22160 -94.09% BenchmarkHaveTruncated-8 151834 4904 -96.77% BenchmarkGlobalTruncated-8 530037 30536 -94.24% benchmark old bytes new bytes delta BenchmarkReplaceAll-8 1765116216 1765305376 +0.01% BenchmarkUpdateOneChanged-8 135085 93043 -31.12% BenchmarkUpdateOneUnchanged-8 134976 92928 -31.15% BenchmarkNeedHalf-8 44758752 44751791 -0.02% BenchmarkHave-8 11845052 11967172 +1.03% BenchmarkGlobal-8 80431136 80431065 -0.00% BenchmarkNeedHalfTruncated-8 46526459 18243543 -60.79% BenchmarkHaveTruncated-8 11348357 418998 -96.31% BenchmarkGlobalTruncated-8 80977672 43116991 -46.75%
2015-10-21 21:33:04 +00:00
func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error {
2016-02-02 11:44:33 +00:00
return o.UnmarshalXDRFrom(&xdr.Unmarshaller{Data: bs})
}
2016-02-02 11:44:33 +00:00
func (o *FileInfoTruncated) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.Name = u.UnmarshalStringMax(8192)
o.Flags = u.UnmarshalUint32()
o.Modified = int64(u.UnmarshalUint64())
(&o.Version).UnmarshalXDRFrom(u)
o.LocalVersion = int64(u.UnmarshalUint64())
_BlocksSize := int(u.UnmarshalUint32())
Don't load block list in ...Truncated methods Speeds up and reduces allocations on those operations, at the price of having a manually tweaked XDR decoder for FileInfoTruncated. benchmark old ns/op new ns/op delta BenchmarkReplaceAll-8 1868198122 1880206886 +0.64% BenchmarkUpdateOneChanged-8 231852 172695 -25.51% BenchmarkUpdateOneUnchanged-8 230624 179341 -22.24% BenchmarkNeedHalf-8 104601744 109461427 +4.65% BenchmarkHave-8 29102480 34105026 +17.19% BenchmarkGlobal-8 150547687 172778045 +14.77% BenchmarkNeedHalfTruncated-8 102471355 76564986 -25.28% BenchmarkHaveTruncated-8 28758368 14277481 -50.35% BenchmarkGlobalTruncated-8 151192913 106070136 -29.84% benchmark old allocs new allocs delta BenchmarkReplaceAll-8 555577 557554 +0.36% BenchmarkUpdateOneChanged-8 1135 587 -48.28% BenchmarkUpdateOneUnchanged-8 1135 587 -48.28% BenchmarkNeedHalf-8 374780 374775 -0.00% BenchmarkHave-8 151992 152085 +0.06% BenchmarkGlobal-8 530033 530135 +0.02% BenchmarkNeedHalfTruncated-8 374699 22160 -94.09% BenchmarkHaveTruncated-8 151834 4904 -96.77% BenchmarkGlobalTruncated-8 530037 30536 -94.24% benchmark old bytes new bytes delta BenchmarkReplaceAll-8 1765116216 1765305376 +0.01% BenchmarkUpdateOneChanged-8 135085 93043 -31.12% BenchmarkUpdateOneUnchanged-8 134976 92928 -31.15% BenchmarkNeedHalf-8 44758752 44751791 -0.02% BenchmarkHave-8 11845052 11967172 +1.03% BenchmarkGlobal-8 80431136 80431065 -0.00% BenchmarkNeedHalfTruncated-8 46526459 18243543 -60.79% BenchmarkHaveTruncated-8 11348357 418998 -96.31% BenchmarkGlobalTruncated-8 80977672 43116991 -46.75%
2015-10-21 21:33:04 +00:00
if _BlocksSize < 0 {
return xdr.ElementSizeExceeded("Blocks", _BlocksSize, 10000000)
2016-02-02 11:44:33 +00:00
} else if _BlocksSize == 0 {
o.Blocks = nil
} else {
if _BlocksSize > 10000000 {
return xdr.ElementSizeExceeded("Blocks", _BlocksSize, 10000000)
2016-02-02 11:44:33 +00:00
}
for i := 0; i < _BlocksSize; i++ {
size := int64(u.UnmarshalUint32())
o.CachedSize += size
u.UnmarshalBytes()
}
Don't load block list in ...Truncated methods Speeds up and reduces allocations on those operations, at the price of having a manually tweaked XDR decoder for FileInfoTruncated. benchmark old ns/op new ns/op delta BenchmarkReplaceAll-8 1868198122 1880206886 +0.64% BenchmarkUpdateOneChanged-8 231852 172695 -25.51% BenchmarkUpdateOneUnchanged-8 230624 179341 -22.24% BenchmarkNeedHalf-8 104601744 109461427 +4.65% BenchmarkHave-8 29102480 34105026 +17.19% BenchmarkGlobal-8 150547687 172778045 +14.77% BenchmarkNeedHalfTruncated-8 102471355 76564986 -25.28% BenchmarkHaveTruncated-8 28758368 14277481 -50.35% BenchmarkGlobalTruncated-8 151192913 106070136 -29.84% benchmark old allocs new allocs delta BenchmarkReplaceAll-8 555577 557554 +0.36% BenchmarkUpdateOneChanged-8 1135 587 -48.28% BenchmarkUpdateOneUnchanged-8 1135 587 -48.28% BenchmarkNeedHalf-8 374780 374775 -0.00% BenchmarkHave-8 151992 152085 +0.06% BenchmarkGlobal-8 530033 530135 +0.02% BenchmarkNeedHalfTruncated-8 374699 22160 -94.09% BenchmarkHaveTruncated-8 151834 4904 -96.77% BenchmarkGlobalTruncated-8 530037 30536 -94.24% benchmark old bytes new bytes delta BenchmarkReplaceAll-8 1765116216 1765305376 +0.01% BenchmarkUpdateOneChanged-8 135085 93043 -31.12% BenchmarkUpdateOneUnchanged-8 134976 92928 -31.15% BenchmarkNeedHalf-8 44758752 44751791 -0.02% BenchmarkHave-8 11845052 11967172 +1.03% BenchmarkGlobal-8 80431136 80431065 -0.00% BenchmarkNeedHalfTruncated-8 46526459 18243543 -60.79% BenchmarkHaveTruncated-8 11348357 418998 -96.31% BenchmarkGlobalTruncated-8 80977672 43116991 -46.75%
2015-10-21 21:33:04 +00:00
}
2016-02-02 11:44:33 +00:00
return u.Error
}
func BlocksToSize(num int) int64 {
if num < 2 {
return protocol.BlockSize / 2
}
return int64(num-1)*protocol.BlockSize + protocol.BlockSize/2
}