Skip to content

sql/catalog/nstree: optimize with lazy initialization, pooling btrees#71927

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/optimize-FlowSetup
Oct 26, 2021
Merged

sql/catalog/nstree: optimize with lazy initialization, pooling btrees#71927
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/optimize-FlowSetup

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

This change comes in response to
#66112 (comment).

The thrust of the change is to lazily initialize the data structures so that
when they are not used, they do not incur cost. Additionally, pool the
underlying tree so that when they are used, the allocations are effectively
free. This was originally deemed unimportant because the connExecutor
descs.Collection is long-lived. Unfortunately, others, as used for the
type resolve in distsql, are not.

name                                           old time/op    new time/op    delta
FlowSetup/vectorize=true/distribute=true-16       145µs ± 2%     139µs ± 3%   -3.94%  (p=0.000 n=19+20)
FlowSetup/vectorize=true/distribute=false-16      141µs ± 3%     134µs ± 2%   -4.66%  (p=0.000 n=18+19)
FlowSetup/vectorize=false/distribute=true-16      138µs ± 4%     132µs ± 4%   -4.23%  (p=0.000 n=20+20)
FlowSetup/vectorize=false/distribute=false-16     133µs ± 3%     127µs ± 3%   -4.41%  (p=0.000 n=20+19)

name                                           old alloc/op   new alloc/op   delta
FlowSetup/vectorize=true/distribute=true-16      38.1kB ± 3%    36.7kB ± 2%   -3.58%  (p=0.000 n=18+18)
FlowSetup/vectorize=true/distribute=false-16     36.2kB ± 0%    34.9kB ± 0%   -3.66%  (p=0.000 n=18+16)
FlowSetup/vectorize=false/distribute=true-16     42.6kB ± 0%    41.3kB ± 0%   -3.11%  (p=0.000 n=17+17)
FlowSetup/vectorize=false/distribute=false-16    41.0kB ± 0%    39.7kB ± 0%   -3.22%  (p=0.000 n=17+17)

name                                           old allocs/op  new allocs/op  delta
FlowSetup/vectorize=true/distribute=true-16         368 ± 0%       314 ± 0%  -14.67%  (p=0.000 n=16+17)
FlowSetup/vectorize=true/distribute=false-16        354 ± 0%       300 ± 0%  -15.25%  (p=0.000 n=17+17)
FlowSetup/vectorize=false/distribute=true-16        338 ± 1%       283 ± 1%  -16.13%  (p=0.000 n=19+19)
FlowSetup/vectorize=false/distribute=false-16       325 ± 0%       271 ± 0%  -16.62%  (p=0.000 n=18+18)

Omitting a release note because I'm doubtful this meaningfully shows up on its
own.

Release note: None

@ajwerner ajwerner requested a review from a team October 25, 2021 14:41
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner
Copy link
Copy Markdown
Contributor Author

cc @yuzefovich

Copy link
Copy Markdown
Member

@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.

Thanks!

Reviewed 10 of 10 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/catalog/descs/uncommitted_descriptors.go, line 86 at r1 (raw file):

func makeUncommittedDescriptors() uncommittedDescriptors {
	ud := uncommittedDescriptors{}

nit: could squash these two lines.

Copy link
Copy Markdown

@postamar postamar left a comment

Choose a reason for hiding this comment

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

This is a change I feel good about. Anyway, it's always nicer to have data structures who's zero-value is valid.

This change comes in response to
cockroachdb#66112 (comment).

The thrust of the change is to lazily initialize the data structures so that
when they are not used, they do not incur cost. Additionally, pool the
underlying tree so that when they are used, the allocations are effectively
free. This was originally deemed unimportant because the connExecutor
descs.Collection is long-lived. Unfortunately, others, as used for the
type resolve in distsql, are not.

```
name                                           old time/op    new time/op    delta
FlowSetup/vectorize=true/distribute=true-16       145µs ± 2%     139µs ± 3%   -3.94%  (p=0.000 n=19+20)
FlowSetup/vectorize=true/distribute=false-16      141µs ± 3%     134µs ± 2%   -4.66%  (p=0.000 n=18+19)
FlowSetup/vectorize=false/distribute=true-16      138µs ± 4%     132µs ± 4%   -4.23%  (p=0.000 n=20+20)
FlowSetup/vectorize=false/distribute=false-16     133µs ± 3%     127µs ± 3%   -4.41%  (p=0.000 n=20+19)

name                                           old alloc/op   new alloc/op   delta
FlowSetup/vectorize=true/distribute=true-16      38.1kB ± 3%    36.7kB ± 2%   -3.58%  (p=0.000 n=18+18)
FlowSetup/vectorize=true/distribute=false-16     36.2kB ± 0%    34.9kB ± 0%   -3.66%  (p=0.000 n=18+16)
FlowSetup/vectorize=false/distribute=true-16     42.6kB ± 0%    41.3kB ± 0%   -3.11%  (p=0.000 n=17+17)
FlowSetup/vectorize=false/distribute=false-16    41.0kB ± 0%    39.7kB ± 0%   -3.22%  (p=0.000 n=17+17)

name                                           old allocs/op  new allocs/op  delta
FlowSetup/vectorize=true/distribute=true-16         368 ± 0%       314 ± 0%  -14.67%  (p=0.000 n=16+17)
FlowSetup/vectorize=true/distribute=false-16        354 ± 0%       300 ± 0%  -15.25%  (p=0.000 n=17+17)
FlowSetup/vectorize=false/distribute=true-16        338 ± 1%       283 ± 1%  -16.13%  (p=0.000 n=19+19)
FlowSetup/vectorize=false/distribute=false-16       325 ± 0%       271 ± 0%  -16.62%  (p=0.000 n=18+18)
```

Omitting a release note because I'm doubtful this meaningfully shows up on its
own.

Release note: None
@ajwerner ajwerner force-pushed the ajwerner/optimize-FlowSetup branch from 9c55629 to 88df2b9 Compare October 26, 2021 16:28
Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

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


pkg/sql/catalog/descs/uncommitted_descriptors.go, line 86 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: could squash these two lines.

Removed the function.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 26, 2021

Build failed (retrying...):

@ajwerner
Copy link
Copy Markdown
Contributor Author

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 26, 2021

Already running a review

@craig craig bot merged commit ff2877c into cockroachdb:master Oct 26, 2021
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 26, 2021

Build succeeded:

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.

4 participants