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

sql: more allocation reductions #57208

Merged
merged 8 commits into from
Nov 4, 2021
Merged

Conversation

jordanlewis
Copy link
Member

@jordanlewis jordanlewis commented Nov 30, 2020

See individual commits for details.

name                                          old time/op    new time/op    delta
FlowSetup/vectorize=true/distribute=true-24      283µs ± 9%     279µs ± 6%    ~     (p=0.316 n=29+30)
FlowSetup/vectorize=true/distribute=false-24     275µs ± 4%     273µs ± 6%    ~     (p=0.107 n=29+30)

name                                          old alloc/op   new alloc/op   delta
FlowSetup/vectorize=true/distribute=true-24     37.9kB ± 1%    37.9kB ± 1%    ~     (p=0.503 n=24+24)
FlowSetup/vectorize=true/distribute=false-24    36.1kB ± 1%    36.0kB ± 0%  -0.22%  (p=0.009 n=25+25)

name                                          old allocs/op  new allocs/op  delta
FlowSetup/vectorize=true/distribute=true-24        361 ± 0%       358 ± 0%  -0.81%  (p=0.000 n=25+26)
FlowSetup/vectorize=true/distribute=false-24       348 ± 1%       346 ± 1%  -0.84%  (p=0.000 n=28+28)

@jordanlewis jordanlewis requested a review from a team as a code owner November 30, 2020 02:51
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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: Nice!

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


pkg/sql/conn_executor_exec.go, line 281 at r7 (raw file):

	queryDone := func(ctx context.Context, res RestrictedCommandResult) {
		if timeoutTicker != nil {
			timeoutTicker.Stop()

[nit] I'd point out that if Stop fails, the callback might still run or is in the process of running (and explain why that's ok)


pkg/sql/conn_executor_exec.go, line 1030 at r13 (raw file):

var (
	eventStartImplicitTxn = fsm.Event(eventTxnStart{ImplicitTxn: fsm.True})

[nit] usually this is written as var eventStartImplicitTxn fsm.Event = eventTxnStart{..}


pkg/sql/opt/memo/interner.go, line 403 at r14 (raw file):

func (h *hasher) HashType(val *types.T) {
	// NOTE: we don't construct a perfect hash of the type, because it's

[nit] can simplify this and just say that we hash the type's OID and a few important fields, and that IsTypeEqual makes the final call about what types are identical.

@tbg tbg added the X-noremind Bots won't notify about PRs with X-noremind label May 6, 2021
Remove a closure for query unregistration as well make the allocation of
a channel lazy.

Release note: None
`connExecutor` used 2 allocating closures on every transaction for
callbacks that are executed on transaction end. This is unnecessary, and
this commit replaces them with methods on the `connExecutor`.

Release note: None
Previously, we unconditionally constructed a new string in a log method
when doing it in a format string under V() was sufficient.

Release note: None
Previously, we used Type.String() as the hash function to intern types.
Constructing a type's string can be very expensive, though, because of
tuple and array types: these require allocating new strings. Tuples are
particularly bad: they require allocating O(log n) in the number of elements
in the tuple!

Now, we construct a hash function that operates on cheaper fields of the
type. Note that it doesn't have to be completely precise, just as
before, since we always re-check type equality later.

Release note: None
Previously, we'd construct a new conn fsm event, allocating each time
due to the interface conversion, on every transaction start.

Now, we use a static one. Events are immutable, so this is safe.

Release note: None
Previously, it was a separate heap allocated object.

Release note: None
@yuzefovich yuzefovich removed the X-noremind Bots won't notify about PRs with X-noremind label Oct 22, 2021
Copy link
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.

I rebased this PR, modified some commits a bit, and addressed all the comments. @RaduBerinde PTAL.

I also dropped the commit about rowenc: cheapen AdjustKeyForInterleave since we're removing the interleaved code anyway. Let me know if you'd rather see it included in the PR.

Reviewed 9 of 23 files at r24, 2 of 2 files at r26, 1 of 2 files at r27, 1 of 2 files at r28, 1 of 2 files at r29, 1 of 3 files at r30, 3 of 3 files at r31.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde and @yuzefovich)


pkg/sql/conn_executor_exec.go, line 281 at r7 (raw file):

Previously, RaduBerinde wrote…

[nit] I'd point out that if Stop fails, the callback might still run or is in the process of running (and explain why that's ok)

I've thought a bit about this, and I'm not sure why that would be ok, so I reverted the change partially.


pkg/sql/conn_executor_exec.go, line 1030 at r13 (raw file):

Previously, RaduBerinde wrote…

[nit] usually this is written as var eventStartImplicitTxn fsm.Event = eventTxnStart{..}

Done.


pkg/sql/opt/memo/interner.go, line 403 at r14 (raw file):

Previously, RaduBerinde wrote…

[nit] can simplify this and just say that we hash the type's OID and a few important fields, and that IsTypeEqual makes the final call about what types are identical.

Done.

@yuzefovich yuzefovich requested review from a team and cucaroach October 25, 2021 21:38
@yuzefovich
Copy link
Member

@cucaroach tagging you as an additional reviewer here.

@yuzefovich
Copy link
Member

Friendly ping @RaduBerinde @cucaroach

Copy link
Contributor

@cucaroach cucaroach 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 23 of 23 files at r24, 1 of 1 files at r25, 2 of 2 files at r26, 2 of 2 files at r27, 2 of 2 files at r28.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde)

@yuzefovich
Copy link
Member

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Nov 4, 2021

Build succeeded:

@craig craig bot merged commit 5e87a89 into cockroachdb:master Nov 4, 2021
@jordanlewis jordanlewis deleted the cancelcheckers branch December 10, 2021 19:45
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.

6 participants