Skip to content

perf(arrow-cast): improve custom temporal formatting performance in ArrayFormatter - #10594

Open
lyne7-sc wants to merge 1 commit into
apache:mainfrom
lyne7-sc:perf/precompile-temporal-formats
Open

perf(arrow-cast): improve custom temporal formatting performance in ArrayFormatter#10594
lyne7-sc wants to merge 1 commit into
apache:mainfrom
lyne7-sc:perf/precompile-temporal-formats

Conversation

@lyne7-sc

@lyne7-sc lyne7-sc commented Aug 8, 2026

Copy link
Copy Markdown

Which issue does this PR close?

  • Closes #NNN.

Rationale for this change

ArrayFormatter currently reparses custom Chrono format strings for every temporal value.

As an ArrayFormatter is typically created once and reused for an array, the parsed format items can instead be prepared once when constructing the formatter and reused for every value.

What changes are included in this PR?

  • Precompile custom temporal format strings when constructing an ArrayFormatter
  • Reuse the compiled format items for date, time, and timestamp values
  • Add benchmarks covering default and custom temporal formats

Are these changes tested?

Yes.

Are there any user-facing changes?

No. There are no public API or behavior changes.

Benchmarks

group                                       main                                    optimized
-----                                       ----                                    ---------
format_temporal/date64/custom_long          1.79  1559.4±47.26µs        ? ?/sec     1.00   872.7±32.05µs        ? ?/sec
format_temporal/date64/custom_short         1.68   797.6±39.91µs        ? ?/sec     1.00   473.7±15.21µs        ? ?/sec
format_temporal/date64/default              1.02   464.7±12.82µs        ? ?/sec     1.00    454.9±8.67µs        ? ?/sec
format_temporal/timestamp/custom_long       1.77  1635.8±175.75µs       ? ?/sec     1.00   925.6±29.74µs        ? ?/sec
format_temporal/timestamp_tz/custom_long    1.54  1939.6±42.35µs        ? ?/sec     1.00  1259.3±41.78µs        ? ?/sec

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-cast labels Aug 8, 2026

@Jefffrey Jefffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can reproduce results locally 👍

format_temporal/date64/default
                        time:   [321.48 µs 322.23 µs 323.09 µs]
+                       change: [−2.6583% −2.0392% −1.4818%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  7 (7.00%) high mild
  4 (4.00%) high severe
format_temporal/date64/custom_short
                        time:   [515.48 µs 517.51 µs 519.66 µs]
+                       change: [−21.775% −21.467% −21.154%] (p = 0.00 < 0.05)
                        Performance has improved.
format_temporal/date64/custom_long
                        time:   [880.49 µs 882.41 µs 884.21 µs]
+                       change: [−32.212% −31.955% −31.705%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
format_temporal/timestamp/custom_long
                        time:   [934.32 µs 937.06 µs 939.70 µs]
+                       change: [−29.966% −29.722% −29.440%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
Benchmarking format_temporal/timestamp_tz/custom_long: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.0s, enable flat sampling, or reduce sample count to 60.
format_temporal/timestamp_tz/custom_long
                        time:   [1.2028 ms 1.2077 ms 1.2126 ms]
+                       change: [−24.125% −23.734% −23.338%] (p = 0.00 < 0.05)
                        Performance has improved.

@lyne7-sc

lyne7-sc commented Aug 9, 2026

Copy link
Copy Markdown
Author

@Jefffrey thanks for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-cast performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants