[#19] transformer: Optimize payload hashers a bit

```
name                 old time/op    new time/op    delta
Transformer/small-8    74.8µs ±11%    73.7µs ±15%    ~     (p=0.529 n=10+10)
Transformer/big-8       1.38s ±11%     1.36s ± 4%    ~     (p=0.796 n=10+10)

name                 old alloc/op   new alloc/op   delta
Transformer/small-8    7.69kB ± 0%    7.67kB ± 0%  -0.21%  (p=0.000 n=10+10)
Transformer/big-8      49.2kB ± 0%    49.0kB ± 0%  -0.48%  (p=0.004 n=10+10)

name                 old allocs/op  new allocs/op  delta
Transformer/small-8       102 ± 0%       101 ± 0%  -0.98%  (p=0.000 n=9+10)
Transformer/big-8         620 ± 1%       609 ± 0%  -1.66%  (p=0.000 n=10+10)
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-02-24 17:01:38 +03:00 committed by Gitea
parent 94c0a607b5
commit 9407f30248

View file

@ -21,7 +21,7 @@ type payloadSizeLimiter struct {
current, parent *object.Object
currentHashers, parentHashers []*payloadChecksumHasher
currentHashers, parentHashers []payloadChecksumHasher
previous []oid.ID
@ -83,7 +83,7 @@ func (s *payloadSizeLimiter) initialize() {
// initialize parent object once (after 1st object)
if ln == 1 {
s.parent = fromObject(s.current)
s.parentHashers = s.currentHashers
s.parentHashers = append(s.parentHashers[:0], s.currentHashers...)
// return source attributes
s.parent.SetAttributes(s.parAttrs...)
@ -117,7 +117,7 @@ func fromObject(obj *object.Object) *object.Object {
func (s *payloadSizeLimiter) initializeCurrent() {
// create payload hashers
s.writtenCurrent = 0
s.currentHashers = payloadHashersForObject(s.WithoutHomomorphicHash)
s.initPayloadHashers()
// compose multi-writer from target and all payload hashers
ws := make([]io.Writer, 0, 1+len(s.currentHashers)+len(s.parentHashers))
@ -135,22 +135,18 @@ func (s *payloadSizeLimiter) initializeCurrent() {
s.chunkWriter = io.MultiWriter(ws...)
}
func payloadHashersForObject(withoutHomomorphicHash bool) []*payloadChecksumHasher {
hashers := make([]*payloadChecksumHasher, 0, 2)
hashers = append(hashers, &payloadChecksumHasher{
func (s *payloadSizeLimiter) initPayloadHashers() {
s.currentHashers = append(s.currentHashers[:0], payloadChecksumHasher{
hasher: sha256.New(),
typ: checksum.SHA256,
})
if !withoutHomomorphicHash {
hashers = append(hashers, &payloadChecksumHasher{
if !s.WithoutHomomorphicHash {
s.currentHashers = append(s.currentHashers, payloadChecksumHasher{
hasher: tz.New(),
typ: checksum.TZ,
})
}
return hashers
}
func (s *payloadSizeLimiter) release(finalize bool) (*AccessIdentifiers, error) {