Skip to content

perf: optimize date_parser / cast string to date (up to 2x faster)#4917

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/date_parser-datafusion-comet-20260714-043541
Open

perf: optimize date_parser / cast string to date (up to 2x faster)#4917
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/date_parser-datafusion-comet-20260714-043541

Conversation

@andygrove

@andygrove andygrove commented Jul 14, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize existing expression.

What changes are included in this PR?

Replaced the per-row chrono NaiveDate construction and duration-to-epoch-day conversion with direct integer calendar validation plus the existing days_from_civil helper, and added a branch-free fast path for the canonical yyyy-mm-dd form that skips trimming, sign and digit-count checks.

How are these changes tested?

Existing tests.

Benchmark (criterion):

  • canonical: 54.56% faster (base 124085ns -> cand 56384ns)
  • mixed: 23.546% faster (base 110311ns -> cand 84337ns)

Full criterion output:

cast_string_to_date/canonical
                        time:   [56.312 µs 56.372 µs 56.441 µs]
                        change: [−54.647% −54.560% −54.464%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 14 outliers among 100 measurements (14.00%)
  1 (1.00%) low severe
  2 (2.00%) low mild
  3 (3.00%) high mild
  8 (8.00%) high severe
cast_string_to_date/mixed
                        time:   [84.211 µs 84.254 µs 84.317 µs]
                        change: [−23.818% −23.546% −23.304%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low severe
  1 (1.00%) low mild
  1 (1.00%) high mild
  3 (3.00%) high severe

@andygrove andygrove changed the title perf: optimize date_parser in datafusion-comet-spark-expr perf: optimize date_parser / cast string to date (up to 2x faster) Jul 14, 2026
@andygrove andygrove marked this pull request as ready for review July 14, 2026 14:45
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.

1 participant