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

coldata: do not allocate wasteful memory for UUIDs #63231

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

yuzefovich
Copy link
Member

Previously, whenever we're allocating a new Bytes vector, we would use
64 bytes as an average element size to decide how large of a flat byte
slice to allocate initially. This is wasteful in case of Uuids because
then we know that each element will be exactly of 16 bytes. This commit
uses that knowledge to remove wasteful allocations.

Release note: None

@yuzefovich yuzefovich requested review from michae2 and a team April 7, 2021 16:32
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 7 of 7 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/col/coldata/bytes.go, line 51 at r1 (raw file):

// that will be added to this Bytes. It can be 0 when the length is unknown in
// which case BytesInitialAllocationFactor will be used as a guess.
func NewBytes(n int, avgElementLength int) *Bytes {

[nit] It's cleaner to have separate constructors instead of special values (e.g. NewBytes, NewBytesWithAvgLength). The one without the length would just call out to the general one with BytesInitialAllocationFactor. For one, you won't have to add a /* avgElementLength */ to all the call sites :)

Previously, whenever we're allocating a new `Bytes` vector, we would use
64 bytes as an average element size to decide how large of a flat byte
slice to allocate initially. This is wasteful in case of Uuids because
then we know that each element will be exactly of 16 bytes. This commit
uses that knowledge to remove wasteful allocations.

Release note: None
Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @michae2 and @RaduBerinde)


pkg/col/coldata/bytes.go, line 51 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] It's cleaner to have separate constructors instead of special values (e.g. NewBytes, NewBytesWithAvgLength). The one without the length would just call out to the general one with BytesInitialAllocationFactor. For one, you won't have to add a /* avgElementLength */ to all the call sites :)

Good point, done.

@craig
Copy link
Contributor

craig bot commented Apr 8, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Apr 8, 2021

Build failed (retrying...):

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @michae2 and @RaduBerinde)

@craig
Copy link
Contributor

craig bot commented Apr 8, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Apr 8, 2021

Build succeeded:

@craig craig bot merged commit 2c50690 into cockroachdb:master Apr 8, 2021
@yuzefovich yuzefovich deleted the vec-uuid branch April 8, 2021 06:13
@knz
Copy link
Contributor

knz commented Apr 13, 2021

@yuzefovich is this a candidate for a backport?

@yuzefovich
Copy link
Member Author

I think so, thanks Raphael.

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.

5 participants