Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colblk: use regular slice in PrefixBytesIter #3872

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

RaduBerinde
Copy link
Member

@RaduBerinde RaduBerinde commented Aug 21, 2024

We currently store an unsafe.Pointer and separate length and
capacities. In many cases in the hot path we have to create a slice
using unsafe.Slice. However unsafe.Slice includes some checks that
we don't need (see here).

In this change we switch to storing a regular slice and converting to
an unsafe.Pointer using unsafe.SliceData (which directly accesses
the pointer field). This improves performance, even while gaining
boundary checks when appending the suffix.

CockroachDataBlockIter/AlphaLen=4,Shared=8,PrefixLen=32,Logical=0,value=8/Next    11.4ns ± 2%    10.6ns ± 1%  -7.32%  (p=0.008 n=5+5)

@RaduBerinde RaduBerinde requested a review from jbowens August 21, 2024 04:47
@RaduBerinde RaduBerinde requested a review from a team as a code owner August 21, 2024 04:47
@cockroach-teamcity
Copy link
Member

This change is Reviewable

We currently store an `unsafe.Pointer` and separate length and
capacities. In many cases in the hot path we have to create a slice
using `unsafe.Slice`. However `unsafe.Slice` includes some checks that
we don't need (see [here](https://github.com/golang/go/blob/f38d42f2c4c6ad0d7cbdad5e1417cac3be2a5dcb/src/runtime/unsafe.go#L53)).

In this change we switch to storing a regular slice and converting to
an `unsafe.Pointer` using `unsafe.SliceData` (which directly accesses
the pointer field). This improves performance, even while gaining
boundary checks when appending the suffix.

```
CockroachDataBlockIter/AlphaLen=4,Shared=8,PrefixLen=32,Logical=0,value=8/Next    11.4ns ± 2%    10.6ns ± 1%  -7.32%  (p=0.008 n=5+5)
```
Copy link
Collaborator

@jbowens jbowens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

nice!

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @RaduBerinde)

@RaduBerinde
Copy link
Member Author

TFTR!

@RaduBerinde RaduBerinde merged commit 8ec212a into cockroachdb:master Aug 22, 2024
11 checks passed
@RaduBerinde RaduBerinde deleted the use-slice-not-buf branch August 22, 2024 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants