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

colmem: optimize SetAccountingHelper #68221

Merged
merged 1 commit into from
Jul 30, 2021

Conversation

yuzefovich
Copy link
Member

This commit optimizes recently introduced SetAccountingHelper in order
to reduce the number of casts per row. Namely, we can perform the cast
from coldata.Vec to a concrete vector only once when a new batch is
allocated and store the concrete vectors to be used during the per-row
accounting. In a single benchmark this showed an improvement of about
3%.

Release note: None

@yuzefovich yuzefovich requested review from jordanlewis, DrewKimball and a team July 29, 2021 07:38
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm:

Are there any types that are of variable size, but the maximum size isn't much larger than the minimum? If so, we could just always use the maximum and overaccount, but avoid some of the overhead.

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


pkg/sql/colmem/allocator.go, line 526 at r1 (raw file):

	// coldata.BatchSize(), this slice will never exceed coldata.BatchSize() in
	// size, and we choose to ignore it for the purposes of memory accounting.
	varSizeDatumSizes []int64

Might be a good idea to add a Close method that releases references to columns and nils out slices.

This commit optimizes recently introduced SetAccountingHelper in order
to reduce the number of casts per row. Namely, we can perform the cast
from `coldata.Vec` to a concrete vector only once when a new batch is
allocated and store the concrete vectors to be used during the per-row
accounting. In a single benchmark this showed an improvement of about
3%.

Release note: None
@yuzefovich yuzefovich force-pushed the set-accounting-helper branch from ca30226 to 9625656 Compare July 30, 2021 04:15
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.

Interesting question. I've just looked over all baseDatumTypeSizes in tree/datum.go, and to me it seems like all variable size types are truly variable, with no upper bound. Also the variable size types that are not bytes-like nor decimals seem pretty out there (quite rare), so it's probably not worth thinking too much about them.

TFTR!

bors r+

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


pkg/sql/colmem/allocator.go, line 526 at r1 (raw file):

Previously, DrewKimball (Drew Kimball) wrote…

Might be a good idea to add a Close method that releases references to columns and nils out slices.

Very good point, done.

@craig
Copy link
Contributor

craig bot commented Jul 30, 2021

Build succeeded:

@craig craig bot merged commit fe1fb73 into cockroachdb:master Jul 30, 2021
@yuzefovich yuzefovich deleted the set-accounting-helper branch July 30, 2021 05:08
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