Skip to content
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

Optimize formatting a bit #1558

Merged
merged 6 commits into from Apr 6, 2024
Merged

Conversation

pitdicker
Copy link
Collaborator

This takes the commits from #1163 that simplify and optimize our formatting code a bit. #1335 took the initial refactor from that PR, so now we can take the more interesting part.

Two commits make better use of match to only accept a formatting item if we also have the date/time/offset fields it needs, instead of using map inside a match arm.

The last commit introduces a couple of optimized number formatting functions. They are the trick that makes our formatting implementations for RFC 2822 and 3339 faster, so lets use them for regular formatting too 😄.

Benchmarks

     Running benches/chrono.rs (target/release/deps/chrono-413c84d256ba35f5)
bench_format            time:   [533.37 ns 535.14 ns 537.22 ns]
                        change: [-22.588% -21.943% -21.284%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe

bench_format_with_items time:   [388.35 ns 389.61 ns 391.09 ns]
                        change: [-29.520% -28.855% -28.271%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

Copy link

codecov bot commented Apr 6, 2024

Codecov Report

Attention: Patch coverage is 94.32624% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 91.80%. Comparing base (7f57dde) to head (e3feef3).

Files Patch % Lines
src/format/formatting.rs 94.32% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1558      +/-   ##
==========================================
+ Coverage   91.78%   91.80%   +0.02%     
==========================================
  Files          37       37              
  Lines       18167    18148      -19     
==========================================
- Hits        16674    16661      -13     
+ Misses       1493     1487       -6     

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

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

Faster in less code, great work!

@pitdicker
Copy link
Collaborator Author

Thank you 😄.

@pitdicker pitdicker merged commit 0cfc405 into chronotope:main Apr 6, 2024
35 checks passed
@pitdicker pitdicker deleted the formatting_optim branch April 6, 2024 12:44
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.

None yet

2 participants