-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87472: util,changefeedccl: streaminger csv writes r=HonoreDB a=HonoreDB The changefeed csv encoder was reading an entire row into memory before encoding it into CSV. There's no particular need to do so, and CSV is now being used at scale, so this PR modifies the CSV writer API slightly to allow for writing fields directly from an iterator. Release justification: Performance tweak to new functionality. Release note: None Co-authored-by: Aaron Zinger <[email protected]>
- Loading branch information
Showing
6 changed files
with
225 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package changefeedccl | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/cdcevent" | ||
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/changefeedbase" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func BenchmarkCSVEncodeWideRow(b *testing.B) { | ||
defer leaktest.AfterTest(b)() | ||
defer log.Scope(b).Close(b) | ||
|
||
// 1024 columns of three runes each. | ||
benchmarkEncodeCSV(b, 1024, 1024*3, 1024) | ||
} | ||
|
||
func BenchmarkCSVEncodeWideRowASCII(b *testing.B) { | ||
defer leaktest.AfterTest(b)() | ||
defer log.Scope(b).Close(b) | ||
|
||
// 1024 columns of three runes each, all ASCII codepoints. | ||
benchmarkEncodeCSV(b, 1024, 1024*3, 127) | ||
} | ||
|
||
func BenchmarkCSVEncodeWideColumnsASCII(b *testing.B) { | ||
defer leaktest.AfterTest(b)() | ||
defer log.Scope(b).Close(b) | ||
|
||
// 3 columns of 1024 runes each, all ASCII codepoints. | ||
benchmarkEncodeCSV(b, 3, 1024*3, 127) | ||
} | ||
|
||
func BenchmarkCSVEncodeWideColumns(b *testing.B) { | ||
defer leaktest.AfterTest(b)() | ||
defer log.Scope(b).Close(b) | ||
|
||
// 3 columns of 1024 runes each. | ||
benchmarkEncodeCSV(b, 3, 1024*3, 1024) | ||
} | ||
|
||
func benchmarkEncodeCSV(b *testing.B, numCols int, numChars int, maxCodepoint int) { | ||
encoder := newCSVEncoder(changefeedbase.EncodingOptions{Format: changefeedbase.OptFormatCSV}) | ||
ctx := context.Background() | ||
vals := make([]string, numCols) | ||
for i := 0; i < numChars; i++ { | ||
vals[i%numCols] += fmt.Sprintf("%c", i%(maxCodepoint+1)) | ||
} | ||
datums := tree.Datums{} | ||
for _, str := range vals { | ||
datums = append(datums, tree.NewDString(str)) | ||
} | ||
row := cdcevent.TestingMakeEventRowFromDatums(datums) | ||
|
||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, err := encoder.EncodeValue(ctx, eventContext{}, row, cdcevent.Row{}) | ||
require.NoError(b, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.