-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
opt: optimize plan gist encoding and decoding #138641
Conversation
|
} | ||
|
||
// Write encodes p in an internal buffer. | ||
func (e *Encoder) Write(p []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was adapted from: https://cs.opensource.google/go/go/+/refs/tags/go1.23.4:src/encoding/base64/base64.go;l=212-286
6b539d3
to
b350644
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r1, 17 of 17 files at r9, 1 of 1 files at r10, 4 of 4 files at r11, 2 of 2 files at r12, 2 of 2 files at r13, 5 of 5 files at r14, 2 of 2 files at r15, 4 of 4 files at r16, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball and @mgartner)
pkg/util/base64/base64.go
line 6 at r11 (raw file):
// included in the file licenses/BSL.txt. // // As of the Change Date specified in that file, in accordance with
nit: I think we use a different license header now.
pkg/util/base64/base64.go
line 35 at r11 (raw file):
} // Init initliazes an Encoder with the given base64.Encoding.
nit: s/initliazes/initializes/
.
pkg/util/base64/base64.go
line 75 at r11 (raw file):
copy(e.buf[:], p) e.nbuf = int8(len(p)) return
nit: no need for this return
since the function now doesn't return anything.
b350644
to
a49c063
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball and @yuzefovich)
pkg/util/base64/base64.go
line 6 at r11 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: I think we use a different license header now.
Good catch, done.
pkg/util/base64/base64.go
line 35 at r11 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit:
s/initliazes/initializes/
.
Done.
pkg/util/base64/base64.go
line 75 at r11 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: no need for this
return
since the function now doesn't return anything.
Done.
Ran some sysbench benchmarks out of curiosity:
|
The plan gist factory is no longer used to decode plan gists. The `planGistDecoder` has been introduced to fulfill this role. Release note: None
`planGistDecoder` now uses a `bytes.Reader` instead of a `bytes.Buffer`. Writing bytes to a `bytes.Buffer` is done with the `Write` method which copies the bytes into the buffer, allocating more space if necessary. A `bytes.Reader` can read over an existing slice of bytes with the `Reset` method without copying or allocating. Release note: None
a49c063
to
f9ee7de
Compare
Sysbench with
|
The `base64.Encoder` utility has been added for encoding byte slice streams into a base64 string. It is adapted from the standard library's base64 encoder returned by `base64.NewEncoder` with some simplifications and an API that helps eliminate unnecessary allocations. Release note: None
The `util` package no longer imports `util/intsets`. This will allow `util/intsets` to import `util` in future commits without creating an import cycle. Release note: None
`base64.Encoder` is now used in `PlanGistFactory` to simplify the logic and reduce allocations. Release note: None
The `intsets.(*Fast).EncodeBase64` method has been added and it is now used to base64 encode intsets directly in plan gists. This avoids the intermediate step of encoding the intset to a temporary buffer before base64 encoding it. Release note: None
A reusable `explain.PlanGistFactory` is now embedded in `optPlanningCtx` to avoid re-allocation of the factory for each query. Release note: None
`explain.NewPlanGistFactory` has been replaced by `(*PlanGistFactory).Init`. Release note: None
f9ee7de
to
29999dc
Compare
TFTR! bors r+ |
PR cockroachdb#138641 caused extra allocations for plan gist factories in optimizer benchmarks. These allocations should not be included in benchmark results, so they have been eliminated. Release note: None
137805: sql/row: use Put instead of CPut when updating value of secondary index r=yuzefovich,stevendanna a=michae2 **sql/row: use Put instead of CPut when updating value of secondary index** When an UPDATE statement changes the value but not the key of a secondary index (e.g. an update to the stored columns of a secondary index) we need to write a new version of the secondary index KV with the new value. We were using a CPutAllowingIfNotExists to do this, which verified that if the KV existed, the expected value was the value before update. But there's no need for this verification. We have other mechanisms to detect a write-write conflict with any other transaction that could have changed the value concurrently. We can simply use a Put to overwrite the previous value. This also matches what we do for the primary index when the PK doesn't change. Epic: None Release note: None --- **sql: change CPutAllowingIfNotExists with nil expValue to CPut** CPutAllowingIfNotExists with empty expValue is equivalent to CPut with empty expValue, so change a few spots to use regular CPut. This almost gets rid of CPutAllowingIfNotExists entirely, but there is at least one spot in backfill (introduced in #138707) that needs to allow for both a non-empty expValue and non-existence of the KV. Also drop "(expecting does not exist)" from CPut tracing, as CPut with empty expValue is now overwhelmingly the most common use of CPut. And this matches the tracing in #138707. Epic: None Release note: None 138243: changefeedccl: fix PTS test r=stevendanna a=asg0451 Fix failing TestPTSRecordProtectsTargetsAndSystemTables test Fixes: #135639 Fixes: #138066 Fixes: #137885 Fixes: #137505 Fixes: #136396 Fixes: #135805 Fixes: #135639 Release note: None 138696: sql: add CHECK EXTERNAL CONNECTION command r=kev-cao a=kev-cao This patch adds the `CHECK EXTERNAL CONNECTION` command and replaces the old `SHOW BACKUP CONNECTION` syntax. Epic: None Release note: None 138740: opt/bench: fix benchmark regression r=mgartner a=mgartner #### opt/bench: fix benchmark regression PR #138641 caused extra allocations for plan gist factories in optimizer benchmarks. These allocations should not be included in benchmark results, so they have been eliminated. Release note: None #### util/base64: use `bytes.Buffer` instead of `strings.Builder` in `Encoder` For our purposes in base64-encoding plan gists, using `bytes.Buffer` in `Encoder` causes fewer allocations, presumably because of a more aggressive growth algorithm. Epic: None Release note: None 138877: opt: reduce allocations when filtering histogram buckets r=mgartner a=mgartner `cat.HistogramBuckets` are now returned and passed by value in `getFilteredBucket` and `(*Histogram).addBucket`, respectively, eliminating some heap allocations. Also, two allocations when building spans from buckets via the `spanBuilder` have been combined into one. The new `(*spanBuilder).init` method simplifies the API by no longer requiring that prefix datums are passed to every invocation of `makeSpanFromBucket`. This also reduces redundant copying of the prefix. Epic: None Release note: None 139029: sql/logictest: disable column family mutations in some cases r=mgartner a=mgartner Random column family mutations are now disabled for `CREATE TABLE` statements with unique, hash-sharded indexes. This prevents the AST from being reserialized with a `UNIQUE` constraint with invalid options, instead of the original `UNIQUE INDEX`. See #65929 and #107398. Epic: None Release note: None 139039: ccl/serverccl: revise `TestTenantVars` cpu time checks r=xinhaoz a=xinhaoz Previously, this test verified that a portion of the test's user cpu time would be less than or equal to the entire tenant user cpu time up to that point. This check is flaky because there's no guarantee that the inactive tenant's cpu time will surpass the test cpu time. We now simply verify that the test cpu times are greater than or equal to the tenant metrics. The test was likely passing before 331596c because the reported tenant cpu time was accounting for the sql server prestart. A tenant's user cpu metrics are tracked from the time the `_status/load` endpoint is registered, and the commit above moved the router setup to occur just after the prestart. Epic: none Fixes: #119329 Release note: None Co-authored-by: Michael Erickson <[email protected]> Co-authored-by: Miles Frankel <[email protected]> Co-authored-by: Kevin Cao <[email protected]> Co-authored-by: Marcus Gartner <[email protected]> Co-authored-by: Xin Hao Zhang <[email protected]>
138740: opt/bench: fix benchmark regression r=mgartner a=mgartner #### opt/bench: fix benchmark regression PR #138641 caused extra allocations for plan gist factories in optimizer benchmarks. These allocations should not be included in benchmark results, so they have been eliminated. Release note: None #### util/base64: use `bytes.Buffer` instead of `strings.Builder` in `Encoder` For our purposes in base64-encoding plan gists, using `bytes.Buffer` in `Encoder` causes fewer allocations, presumably because of a more aggressive growth algorithm. Epic: None Release note: None 139070: spanconfigkvsubscriberccl: run expensive tests in heavy pool r=rafiss a=rafiss We have seen this timeout under race over the past few weeks, so this patch gives the test more resources under race/deadlock. informs: #138032 Release note: None 139074: authors: add Manu Gomez to authors r=InManuBytes a=InManuBytes Epic: None Release note: None Co-authored-by: Marcus Gartner <[email protected]> Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Manu Gomez <[email protected]>
PR cockroachdb#138641 caused extra allocations for plan gist factories in optimizer benchmarks. These allocations should not be included in benchmark results, so they have been eliminated. Release note: None
PR cockroachdb#138641 caused extra allocations for plan gist factories in optimizer benchmarks. These allocations should not be included in benchmark results, so they have been eliminated. Release note: None
PR cockroachdb#138641 caused extra allocations for plan gist factories in optimizer benchmarks. These allocations should not be included in benchmark results, so they have been eliminated. Release note: None
opt/exec: split plan gist factory and decoder
The plan gist factory is no longer used to decode plan gists. The
planGistDecoder
has been introduced to fulfill this role.Release note: None
opt/exec: use
bytes.Reader
inplanGistDecoder
planGistDecoder
now uses abytes.Reader
instead of abytes.Buffer
.Writing bytes to a
bytes.Buffer
is done with theWrite
method whichcopies the bytes into the buffer, allocating more space if necessary. A
bytes.Reader
can read over an existing slice of bytes with theReset
method without copying or allocating.
Release note: None
util/base64: add
Encoder
The
base64.Encoder
utility has been added for encoding byte slicestreams into a base64 string. It is adapted from the standard library's
base64 encoder returned by
base64.NewEncoder
with some simplificationsand an API that helps eliminate unnecessary allocations.
Release note: None
util: break dependence on util/intsets
The
util
package no longer importsutil/intsets
. This will allowutil/intsets
to importutil
in future commits without creating animport cycle.
Release note: None
opt/exec: use
base64.Encoder
for plan gist encodingbase64.Encoder
is now used inPlanGistFactory
to simplify the logicand reduce allocations.
Release note: None
opt/exec: encode plan gist intsets directly as base64
The
intsets.(*Fast).EncodeBase64
method has been added and it is nowused to base64 encode intsets directly in plan gists. This avoids the
intermediate step of encoding the intset to a temporary buffer before
base64 encoding it.
Release note: None
sql: embed
explain.PlanGistFactory
inoptPlanningCtx
A reusable
explain.PlanGistFactory
is now embedded inoptPlanningCtx
to avoid re-allocation of the factory for each query.
Release note: None
opt/exec: remove
explain.NewPlanGistFactory
explain.NewPlanGistFactory
has been replaced by(*PlanGistFactory).Init
.Epic: None
Release note: None