2023-02-18 07:13:14 +00:00
package transformer
import (
2023-04-21 10:04:44 +00:00
"context"
2023-02-18 07:13:14 +00:00
"crypto/rand"
2023-02-24 13:21:56 +00:00
"crypto/sha256"
2023-02-18 07:13:14 +00:00
"testing"
2023-03-16 06:51:03 +00:00
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
2023-02-18 07:13:14 +00:00
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/stretchr/testify/require"
)
func TestTransformer ( t * testing . T ) {
const maxSize = 100
tt := new ( testTarget )
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
target , pk := newPayloadSizeLimiter ( maxSize , 0 , func ( ) ObjectWriter { return tt } )
2023-02-18 07:13:14 +00:00
cnr := cidtest . ID ( )
2023-02-23 14:13:13 +00:00
hdr := newObject ( cnr )
2023-02-18 07:13:14 +00:00
2023-02-24 13:21:56 +00:00
var owner user . ID
user . IDFromKey ( & owner , pk . PrivateKey . PublicKey )
2023-11-21 08:35:10 +00:00
hdr . SetOwnerID ( owner )
2023-02-24 13:21:56 +00:00
2023-02-18 07:13:14 +00:00
expectedPayload := make ( [ ] byte , maxSize * 2 + maxSize / 2 )
_ , _ = rand . Read ( expectedPayload )
2023-04-21 10:04:44 +00:00
ids := writeObject ( t , context . Background ( ) , target , hdr , expectedPayload )
2023-02-18 07:13:14 +00:00
require . Equal ( t , 4 , len ( tt . objects ) ) // 3 parts + linking object
var actualPayload [ ] byte
for i := range tt . objects {
childCnr , ok := tt . objects [ i ] . ContainerID ( )
require . True ( t , ok )
require . Equal ( t , cnr , childCnr )
require . Equal ( t , objectSDK . TypeRegular , tt . objects [ i ] . Type ( ) )
2023-11-21 08:35:10 +00:00
require . Equal ( t , owner , tt . objects [ i ] . OwnerID ( ) )
2023-02-18 07:13:14 +00:00
payload := tt . objects [ i ] . Payload ( )
require . EqualValues ( t , tt . objects [ i ] . PayloadSize ( ) , len ( payload ) )
actualPayload = append ( actualPayload , payload ... )
2023-02-24 13:21:56 +00:00
if len ( payload ) != 0 {
cs , ok := tt . objects [ i ] . PayloadChecksum ( )
require . True ( t , ok )
h := sha256 . Sum256 ( payload )
require . Equal ( t , h [ : ] , cs . Value ( ) )
}
2023-05-03 08:09:12 +00:00
require . True ( t , tt . objects [ i ] . VerifyIDSignature ( ) )
2023-02-18 07:13:14 +00:00
switch i {
case 0 , 1 :
require . EqualValues ( t , maxSize , len ( payload ) )
2023-05-03 08:09:12 +00:00
require . Nil ( t , tt . objects [ i ] . Parent ( ) )
2023-02-18 07:13:14 +00:00
case 2 :
require . EqualValues ( t , maxSize / 2 , len ( payload ) )
2023-05-03 08:09:12 +00:00
parent := tt . objects [ i ] . Parent ( )
require . NotNil ( t , parent )
require . Nil ( t , parent . SplitID ( ) )
require . True ( t , parent . VerifyIDSignature ( ) )
2023-02-18 07:13:14 +00:00
case 3 :
parID , ok := tt . objects [ i ] . ParentID ( )
require . True ( t , ok )
2023-02-17 10:00:27 +00:00
require . Equal ( t , ids . ParentID , & parID )
2023-05-03 08:09:12 +00:00
children := tt . objects [ i ] . Children ( )
2024-09-03 10:20:30 +00:00
for j := range i {
2023-05-03 08:09:12 +00:00
id , ok := tt . objects [ j ] . ID ( )
require . True ( t , ok )
require . Equal ( t , id , children [ j ] )
}
2023-02-18 07:13:14 +00:00
}
}
require . Equal ( t , expectedPayload , actualPayload )
2023-02-24 13:21:56 +00:00
t . Run ( "parent checksum" , func ( t * testing . T ) {
cs , ok := ids . ParentHeader . PayloadChecksum ( )
require . True ( t , ok )
h := sha256 . Sum256 ( expectedPayload )
require . Equal ( t , h [ : ] , cs . Value ( ) )
} )
2023-02-18 07:13:14 +00:00
}
2023-02-23 14:13:13 +00:00
func newObject ( cnr cid . ID ) * objectSDK . Object {
2023-02-18 07:13:14 +00:00
ver := version . Current ( )
hdr := objectSDK . New ( )
hdr . SetContainerID ( cnr )
hdr . SetType ( objectSDK . TypeRegular )
hdr . SetVersion ( & ver )
2023-02-23 14:13:13 +00:00
return hdr
}
2023-07-07 12:34:31 +00:00
func writeObject ( t * testing . T , ctx context . Context , target ChunkedObjectWriter , header * objectSDK . Object , payload [ ] byte ) * AccessIdentifiers {
2023-04-21 10:04:44 +00:00
require . NoError ( t , target . WriteHeader ( ctx , header ) )
2023-02-23 14:13:13 +00:00
2023-04-21 10:04:44 +00:00
_ , err := target . Write ( ctx , payload )
2023-02-23 14:13:13 +00:00
require . NoError ( t , err )
2023-04-21 10:04:44 +00:00
ids , err := target . Close ( ctx )
2023-02-23 14:13:13 +00:00
require . NoError ( t , err )
return ids
}
func BenchmarkTransformer ( b * testing . B ) {
hdr := newObject ( cidtest . ID ( ) )
2023-02-18 07:13:14 +00:00
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
const (
// bufferSize is taken from https://git.frostfs.info/TrueCloudLab/frostfs-sdk-go/src/commit/670619d2426fee233a37efe21a0471989b16a4fc/pool/pool.go#L1825
bufferSize = 3 * 1024 * 1024
smallSize = 8 * 1024
bigSize = 64 * 1024 * 1024 * 9 / 2 // 4.5 parts
)
2023-02-18 07:13:14 +00:00
b . Run ( "small" , func ( b * testing . B ) {
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
b . Run ( "no size hint" , func ( b * testing . B ) {
benchmarkTransformer ( b , hdr , smallSize , 0 , 0 )
} )
b . Run ( "no size hint, with buffer" , func ( b * testing . B ) {
benchmarkTransformer ( b , hdr , smallSize , 0 , bufferSize )
} )
b . Run ( "with size hint, with buffer" , func ( b * testing . B ) {
benchmarkTransformer ( b , hdr , smallSize , smallSize , bufferSize )
} )
2023-02-18 07:13:14 +00:00
} )
b . Run ( "big" , func ( b * testing . B ) {
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
b . Run ( "no size hint" , func ( b * testing . B ) {
benchmarkTransformer ( b , hdr , bigSize , 0 , 0 )
} )
b . Run ( "no size hint, with buffer" , func ( b * testing . B ) {
benchmarkTransformer ( b , hdr , bigSize , 0 , bufferSize )
} )
b . Run ( "with size hint, with buffer" , func ( b * testing . B ) {
benchmarkTransformer ( b , hdr , bigSize , bigSize , bufferSize )
} )
2023-02-18 07:13:14 +00:00
} )
}
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
func benchmarkTransformer ( b * testing . B , header * objectSDK . Object , payloadSize , sizeHint , bufferSize int ) {
2023-02-18 07:13:14 +00:00
const maxSize = 64 * 1024 * 1024
payload := make ( [ ] byte , payloadSize )
2023-04-21 10:04:44 +00:00
ctx := context . Background ( )
2023-02-18 07:13:14 +00:00
b . ReportAllocs ( )
b . ResetTimer ( )
2024-09-03 10:20:30 +00:00
for range b . N {
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
f , _ := newPayloadSizeLimiter ( maxSize , uint64 ( sizeHint ) , func ( ) ObjectWriter { return benchTarget { } } )
2023-04-21 10:04:44 +00:00
if err := f . WriteHeader ( ctx , header ) ; err != nil {
2023-02-18 07:13:14 +00:00
b . Fatalf ( "write header: %v" , err )
}
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
if bufferSize == 0 {
if _ , err := f . Write ( ctx , payload ) ; err != nil {
b . Fatalf ( "write: %v" , err )
}
} else {
j := 0
for ; j + bufferSize < payloadSize ; j += bufferSize {
if _ , err := f . Write ( ctx , payload [ j : j + bufferSize ] ) ; err != nil {
b . Fatalf ( "write: %v" , err )
}
}
if _ , err := f . Write ( ctx , payload [ j : payloadSize ] ) ; err != nil {
b . Fatalf ( "write: %v" , err )
}
2023-02-18 07:13:14 +00:00
}
2023-04-21 10:04:44 +00:00
if _ , err := f . Close ( ctx ) ; err != nil {
2023-02-18 07:13:14 +00:00
b . Fatalf ( "close: %v" , err )
}
}
}
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
func newPayloadSizeLimiter ( maxSize uint64 , sizeHint uint64 , nextTarget TargetInitializer ) ( ChunkedObjectWriter , * keys . PrivateKey ) {
2023-02-18 07:13:14 +00:00
p , err := keys . NewPrivateKey ( )
if err != nil {
panic ( err )
}
2023-02-18 07:43:34 +00:00
return NewPayloadSizeLimiter ( Params {
Key : & p . PrivateKey ,
2023-05-03 08:18:08 +00:00
NextTargetInit : nextTarget ,
2023-02-18 07:43:34 +00:00
NetworkState : dummyEpochSource ( 123 ) ,
MaxSize : maxSize ,
[#188] transformer: Allow to provide size hint
For big objects with known size we can optimize allocation patterns
by providing size hint. As with any hint, it does not affect transformer
functionality: slices with capacity > MaxSize are never allocated.
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
│ out │
│ sec/op │
Transformer/small/no_size_hint-8 65.44µ ± 3%
Transformer/small/no_size_hint,_with_buffer-8 64.24µ ± 5%
Transformer/small/with_size_hint,_with_buffer-8 58.70µ ± 5%
Transformer/big/no_size_hint-8 367.8m ± 3%
Transformer/big/no_size_hint,_with_buffer-8 562.7m ± 0%
Transformer/big/with_size_hint,_with_buffer-8 385.6m ± 7%
geomean 5.197m
│ out │
│ B/op │
Transformer/small/no_size_hint-8 13.40Ki ± 0%
Transformer/small/no_size_hint,_with_buffer-8 13.40Ki ± 0%
Transformer/small/with_size_hint,_with_buffer-8 13.39Ki ± 0%
Transformer/big/no_size_hint-8 288.0Mi ± 0%
Transformer/big/no_size_hint,_with_buffer-8 1.390Gi ± 0%
Transformer/big/with_size_hint,_with_buffer-8 288.0Mi ± 0%
geomean 2.533Mi
│ out │
│ allocs/op │
Transformer/small/no_size_hint-8 92.00 ± 0%
Transformer/small/no_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/small/with_size_hint,_with_buffer-8 92.00 ± 0%
Transformer/big/no_size_hint-8 546.5 ± 0%
Transformer/big/no_size_hint,_with_buffer-8 607.5 ± 0%
Transformer/big/with_size_hint,_with_buffer-8 545.5 ± 0%
geomean 228.1
```
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-10-26 15:13:54 +00:00
SizeHint : sizeHint ,
2023-02-18 07:43:34 +00:00
WithoutHomomorphicHash : true ,
2023-02-18 07:13:14 +00:00
} ) , p
}
type dummyEpochSource uint64
func ( s dummyEpochSource ) CurrentEpoch ( ) uint64 {
return uint64 ( s )
}
type benchTarget struct { }
2023-07-07 12:34:31 +00:00
func ( benchTarget ) WriteObject ( context . Context , * objectSDK . Object ) error {
2023-02-18 07:13:14 +00:00
return nil
}
type testTarget struct {
objects [ ] * objectSDK . Object
}
2023-07-07 12:34:31 +00:00
func ( tt * testTarget ) WriteObject ( _ context . Context , o * objectSDK . Object ) error {
tt . objects = append ( tt . objects , o )
return nil // AccessIdentifiers should not be used.
2023-02-18 07:13:14 +00:00
}