Skip to content

Optimize datetime formatting code - #12626

Merged
davidhewitt merged 1 commit into
mainfrom
dh/dt-optimization
Dec 17, 2025
Merged

davidhewitt merged 1 commit into
mainfrom
dh/dt-optimization

Conversation

@davidhewitt

Copy link
Copy Markdown
Contributor

Change Summary

I was looking at cleaning up the json_key methods a bit (they create a lot of temporary String allocations). I found that these datetime methods needed particular work to clean up, so I'm pushing this first and separately:

  • Use serializer.collect_str(s) instead of serializer.serialize_str(&s.to_string())
  • Add fast paths for converting exact datetime types to speedate types without having to go through Python attributes.

Related issue number

N/A

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@github-actions github-actions Bot added the relnotes-fix Used for bugfixes. label Dec 14, 2025
@codspeed

codspeed Bot commented Dec 14, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #12626 will degrade performances by 10.44%

Comparing dh/dt-optimization (3038c43) with main (0329e09)

Summary

⚡ 7 improvements
❌ 1 regression
✅ 203 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
⚡ test_core_future 18.4 µs 15.9 µs +15.74%
⚡ test_date_from_datetime 23.7 µs 19.1 µs +23.64%
⚡ test_core_future 26.3 µs 22.3 µs +18%
❌ test_list_of_strs_json_uncached 378.8 µs 423 µs -10.44%
⚡ test_north_star_dump_json 29.7 ms 26.7 ms +10.9%
⚡ test_datetime_milliseconds 26.2 µs 21.5 µs +22.07%
⚡ test_datetime 29 µs 24.2 µs +19.66%
⚡ test_datetime_seconds 26.1 µs 21.6 µs +20.93%

@davidhewitt davidhewitt added relnotes-performance Used for performance improvements. and removed relnotes-fix Used for bugfixes. labels Dec 14, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

@davidhewitt

Copy link
Copy Markdown
Contributor Author

Regression is unrelated volatility, all the gains are relevant and real 🎉

@davidhewitt
davidhewitt requested a review from Viicos December 14, 2025 15:27
@davidhewitt
davidhewitt merged commit 469ba09 into main Dec 17, 2025
114 of 118 checks passed
@davidhewitt
davidhewitt deleted the dh/dt-optimization branch December 17, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes-performance Used for performance improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants