Skip to content

Conversation

@coderfender
Copy link
Contributor

Which issue does this PR close?

Closes #2981

Rationale for this change

What changes are included in this PR?

How are these changes tested?

@coderfender
Copy link
Contributor Author

Initial benchmarks showed improvement to match with Spark's performance. I will continue to profile the code to see if we can squeeze in additional optimization

@coderfender coderfender changed the title perf: Improve string to date perf perf: Improve string to int perf Jan 1, 2026
@coderfender coderfender marked this pull request as ready for review January 3, 2026 02:57
cast_array.append_value(cast_value);
} else {
cast_array.append_null()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made null check conditional to remove unwanted branching

if len == 1 {
return none_or_err(eval_mode, type_name, str);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same (removed unwanted If branching)

let mut parse_sign_and_digits = true;

for (i, ch) in trimmed_str.char_indices() {
for &ch in &trimmed_bytes[idx..] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner and faster approach to access the chars directly

@coderfender
Copy link
Contributor Author

Results :

================================================================================================
Running benchmark cast operation from : StringType to : IntegerType
================================================================================================

OpenJDK 64-Bit Server VM 17.0.16+8-LTS on Mac OS X 16.0
Apple M2 Max
Cast function to : IntegerType , ansi mode enabled : false:  Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
------------------------------------------------------------------------------------------------------------------------------------------
Spark                                                                 668            683          14         15.7          63.8       1.0X
Comet (Scan)                                                          708            739          30         14.8          67.5       0.9X
Comet (Scan + Exec)                                                   816            829          18         12.9          77.8       0.8X


================================================================================================
Running benchmark cast operation from : StringType to : ShortType
================================================================================================

OpenJDK 64-Bit Server VM 17.0.16+8-LTS on Mac OS X 16.0
Apple M2 Max
Cast function to : ShortType , ansi mode enabled : false:  Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
----------------------------------------------------------------------------------------------------------------------------------------
Spark                                                               689            692           2         15.2          65.7       1.0X
Comet (Scan)                                                        639            658          21         16.4          60.9       1.1X
Comet (Scan + Exec)                                                 793            798           4         13.2          75.6       0.9X


================================================================================================
Running benchmark cast operation from : StringType to : ByteType
================================================================================================

OpenJDK 64-Bit Server VM 17.0.16+8-LTS on Mac OS X 16.0
Apple M2 Max
Cast function to : ByteType , ansi mode enabled : false:  Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
---------------------------------------------------------------------------------------------------------------------------------------
Spark                                                              659            694          39         15.9          62.9       1.0X
Comet (Scan)                                                       639            655          12         16.4          60.9       1.0X
Comet (Scan + Exec)                                                795            810          20         13.2          75.8       0.8X

@coderfender
Copy link
Contributor Author

Proceeding with some rather unsafe options to see if we can squeeze in further optimizations

@codecov-commenter
Copy link

codecov-commenter commented Jan 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.56%. Comparing base (f09f8af) to head (2b331f0).
⚠️ Report is 814 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3017      +/-   ##
============================================
+ Coverage     56.12%   59.56%   +3.43%     
- Complexity      976     1379     +403     
============================================
  Files           119      167      +48     
  Lines         11743    15496    +3753     
  Branches       2251     2569     +318     
============================================
+ Hits           6591     9230    +2639     
- Misses         4012     4968     +956     
- Partials       1140     1298     +158     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderfender
Copy link
Contributor Author

  | Type | Before (main) | After (feature) | Improvement |
  |------|---------------|-----------------|-------------|
  | i8   | 26.5 µs       | 19.8 µs         | 1.34x (34%) |
  | i16  | 27.2 µs       | 21.3 µs         | 1.27x (27%) |
  | i32  | 26.8 µs       | 19.9 µs         | 1.34x (34%) |
  | i64  | 31.8 µs       | 25.6 µs         | 1.24x (24%) |

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.

Improve performance of cast from string to integral types

2 participants