-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48712][SQL] Perf Improvement for encode with empty values or UTF-8 charset #47096
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d36c1e
[SPARK-48712][SQL] Perf Improvement for encode with empty value or UT…
yaooqinn 4d6c49d
add more case
yaooqinn 64dccfe
add tests
yaooqinn 8903ab6
update golden files for 17
yaooqinn 7db3f31
update golden files for 21
yaooqinn 5c4b5d0
add more tests
yaooqinn 9a8c302
Merge branch 'master' into SPARK-48712
yaooqinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,8 @@ | ||
| OpenJDK 64-Bit Server VM 21.0.3+9-LTS on Linux 6.5.0-1022-azure | ||
| AMD EPYC 7763 64-Core Processor | ||
| encode: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative | ||
| ------------------------------------------------------------------------------------------------------------------------ | ||
| UTF-32 47469 47482 19 0.2 4746.9 1.0X | ||
| UTF-16 57463 57487 35 0.2 5746.3 0.8X | ||
| UTF-8 2803 2805 3 3.6 280.3 16.9X | ||
|
|
This file contains hidden or 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,8 @@ | ||
| OpenJDK 64-Bit Server VM 17.0.11+9-LTS on Linux 6.5.0-1022-azure | ||
| AMD EPYC 7763 64-Core Processor | ||
| encode: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative | ||
| ------------------------------------------------------------------------------------------------------------------------ | ||
| UTF-32 31107 31205 138 0.3 3110.7 1.0X | ||
| UTF-16 47904 47934 43 0.2 4790.4 0.6X | ||
| UTF-8 2957 2978 30 3.4 295.7 10.5X | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
73 changes: 73 additions & 0 deletions
73
sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/EncodeBenchmark.scala
This file contains hidden or 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,73 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.execution.benchmark | ||
|
|
||
| import org.apache.spark.benchmark.Benchmark | ||
|
|
||
| /** | ||
| * Benchmark for encode | ||
| * To run this benchmark: | ||
| * {{{ | ||
| * 1. without sbt: | ||
| * bin/spark-submit --class <this class> --jars <spark core test jar> <sql core test jar> | ||
| * 2. build/sbt "sql/Test/runMain <this class>" | ||
| * 3. generate result: | ||
| * SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/Test/runMain <this class>" | ||
| * Results will be written to "benchmarks/EncodeBenchmark-results.txt". | ||
| * }}} | ||
| */ | ||
| object EncodeBenchmark extends SqlBasedBenchmark { | ||
| import spark.implicits._ | ||
| private val N = 10L * 1000 * 1000 | ||
|
|
||
| override def runBenchmarkSuite(mainArgs: Array[String]): Unit = { | ||
| withTempPath { path => | ||
| // scalastyle:off nonascii | ||
| val exprs = Seq( | ||
| "", | ||
| "Spark", | ||
| "白日依山尽,黄河入海流。欲穷千里目,更上一层楼。", | ||
| "το Spark είναι το πιο δημοφιλές πλαίσιο επεξεργασίας μεγάλων δεδομένων παγκοσμίως", | ||
| "세계에서 가장 인기 있는 빅데이터 처리 프레임워크인 Spark", | ||
| "Sparkは世界で最も人気のあるビッグデータ処理フレームワークである。") | ||
| // scalastyle:off nonascii | ||
|
|
||
| spark.range(N).map { i => | ||
| val idx = (i % 6).toInt | ||
| val str = exprs(idx) | ||
| (str, str * 3, str * 5, str * 9, "") | ||
| }.write.parquet(path.getCanonicalPath) | ||
|
|
||
| val benchmark = new Benchmark("encode", N, output = output) | ||
| def addBenchmarkCase(charset: String): Unit = { | ||
| benchmark.addCase(charset) { _ => | ||
| spark.read.parquet(path.getCanonicalPath).selectExpr( | ||
| s"encode(_1, '$charset')", | ||
| s"encode(_2, '$charset')", | ||
| s"encode(_3, '$charset')", | ||
| s"encode(_4, '$charset')", | ||
| s"encode(_5, '$charset')").noop() | ||
| } | ||
| } | ||
| addBenchmarkCase("UTF-32") | ||
| addBenchmarkCase("UTF-16") | ||
| addBenchmarkCase("UTF-8") | ||
| benchmark.run() | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is actually a behavior change. If the input bytes are not valid utf 8 encoding, previously the result was not the same as the input bytes, but now it is.
We should either remove this utf 8 shortcut, or check the input bytes to see if it's valid utf8 encoding first.
cc @yaooqinn
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.
Do you mean that we will encode the unmappable characters to mojibakes before this PR, but now we use its identity?
Do you think we can call
input.isValidto check here?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.
yea I think so. For the happy path it's still faster than doing the actual encoding, and invalid utf8 bytes should be rare so it's ok to have an extra
isValidcall.