Skip to content

Commit

Permalink
objstorage: optimize MemObj.NewReadHandle
Browse files Browse the repository at this point in the history
Better implementation for `MemObj.NewReadHandle` which doesn't
allocate (the allocation shows up in profiles and is a red-herring as
the production path would use a preallocated handle).
  • Loading branch information
RaduBerinde committed Oct 19, 2024
1 parent 29cc16b commit a46949c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion objstorage/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,24 @@ func (f *MemObj) Size() int64 {
return int64(f.buf.Len())
}

type memObjReadHandle MemObj

var _ ReadHandle = (*memObjReadHandle)(nil)

func (h *memObjReadHandle) ReadAt(ctx context.Context, p []byte, off int64) error {
return (*MemObj)(h).ReadAt(ctx, p, off)
}

func (h *memObjReadHandle) Close() error {
}

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-build-other (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-build-other (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / code-cover-gen

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-cgo (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-32bit (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-32bit (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-32bit (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-32bit (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-macos (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-crossversion (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-crossversion (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-crossversion (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-crossversion (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-no-invariants (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-windows (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-windows (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-race (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-race (1.22)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-race (1.23)

missing return

Check failure on line 69 in objstorage/test_utils.go

View workflow job for this annotation

GitHub Actions / go-linux-race (1.23)

missing return

func (h *memObjReadHandle) SetupForCompaction() {
}

func (h *memObjReadHandle) RecordCacheHit(ctx context.Context, offset, size int64) {
}

// NewReadHandle is part of the Readable interface.
func (f *MemObj) NewReadHandle(readBeforeSize ReadBeforeSize) ReadHandle {
return &NoopReadHandle{readable: f}
return (*memObjReadHandle)(f)
}

0 comments on commit a46949c

Please sign in to comment.