-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(expr): optimize casting to varchar (#7066)
This PR optimizes the performance of casting values to varchar. It introduced write API for `ToText`, so that strings can be directly written to array buffers without generating String. The display function of interval and timestampz was also optimized. <img width="581" alt="perf-cast" src="https://user-images.githubusercontent.com/15158738/209610088-859f0f77-5272-4cb8-bbe3-f743bc0cbe97.png"> <details> <summary>Click to show full results</summary> bench | Before time(us) | After time(us) | Change(%) | Speedup -- | -- | -- | -- | -- cast(timestampz->varchar) | 508.640 | 121.600 | -76.1% | 3.2 cast(timestamp->varchar) | 166.200 | 58.245 | -65.0% | 1.9 cast(float64->varchar) | 78.386 | 57.597 | -26.5% | 0.4 cast(float32->varchar) | 57.903 | 37.384 | -35.4% | 0.5 cast(date->varchar) | 86.896 | 32.669 | -62.4% | 1.7 cast(time->varchar) | 47.508 | 28.428 | -40.2% | 0.7 cast(decimal->varchar) | 67.682 | 28.317 | -58.2% | 1.4 cast(int16->varchar) | 29.532 | 12.337 | -58.2% | 1.4 cast(int64->varchar) | 52.043 | 12.319 | -76.3% | 3.2 cast(int32->varchar) | 28.863 | 12.258 | -57.5% | 1.4 cast(boolean->varchar) | 26.826 | 6.396 | -76.2% | 3.2 bool_out(boolean) | 25.480 | 5.126 | -79.9% | 4.0 </details> The `writer` argument of string functions was also changed from `StringWriter<'_>` to `&mut dyn Write`, making them decouple from array. I tried to use `&mut impl Write` but was blocked by annoying lifetime issues. Anyways, the performance of these operations is still slightly improved: <img width="600" alt="perf-string-ops" src="https://user-images.githubusercontent.com/15158738/209610928-8036e4d1-e994-4178-8ce4-ff1340877e47.png"> <details> <summary>Click to show full results</summary> bench | Before time(us) | After time(us) | Change(%) | Speedup -- | -- | -- | -- | -- rtrim(varchar,varchar) | 21.780 | 15.768 | -27.6% | 0.4 substr(varchar,int32,int32) | 11.126 | 8.090 | -27.3% | 0.4 rtrim(varchar) | 10.537 | 7.712 | -26.8% | 0.4 substr(varchar,int32) | 9.198 | 7.111 | -22.7% | 0.3 ltrim(varchar) | 9.661 | 8.010 | -17.1% | 0.2 trim(varchar) | 11.308 | 9.618 | -14.9% | 0.2 overlay(varchar,varchar,int32,int32) | 17.107 | 14.697 | -14.1% | 0.2 overlay(varchar,varchar,int32) | 13.408 | 12.007 | -10.4% | 0.1 ltrim(varchar,varchar) | 21.198 | 19.021 | -10.3% | 0.1 trim(varchar,varchar) | 20.876 | 19.205 | -8.0% | 0.1 split_part(varchar,varchar,int32) | 30.708 | 29.293 | -4.6% | 0.0 md5(varchar) | 346.010 | 331.670 | -4.1% | 0.0 </details> Approved-By: BowenXiao1999 Approved-By: BugenZhao
- Loading branch information
1 parent
2d74a67
commit 29270ca
Showing
27 changed files
with
423 additions
and
551 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
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
Oops, something went wrong.