Skip to content

Conversation

@FusRoman
Copy link
Contributor

Summary

This PR reduces the overhead of UT1 conversions by:

  • Borrowing Ut1Provider instead of moving it (no more large Vec clones on hot paths).
  • Replacing the reverse linear scan in Epoch::ut1_offset with an O(log n) lookup using slice::partition_point, plus a fast-path when the query epoch is ≥ the last record.
  • Making the EOP parser (Ut1Provider::from_eop_data) single-pass with no per-line allocation and a conditional sort (only sort if input is detected out of order).
  • Adding ergonomic, zero-copy iteration helpers on Ut1Provider (iter, as_slice, and IntoIterator for &Ut1Provider).

These changes eliminate unnecessary cloning, reduce allocations, and make UT1 offset queries scale with the number of records.

Breaking change & Migration

This PR introduces a small breaking change: UT1 conversion functions now take a
borrowed provider (&Ut1Provider) instead of owning it. The migration is a
one-liner at each call site.

What changed

- pub fn from_ut1_duration(duration: Duration, provider: Ut1Provider) -> Self
+ pub fn from_ut1_duration(duration: Duration, provider: &Ut1Provider) -> Self

- pub fn to_ut1_duration(&self, provider: Ut1Provider) -> Duration
+ pub fn to_ut1_duration(&self, provider: &Ut1Provider) -> Duration

- pub fn to_ut1(&self, provider: Ut1Provider) -> Self
+ pub fn to_ut1(&self, provider: &Ut1Provider) -> Self

close #418

- Change Epoch::{to_ut1,to_ut1_duration,ut1_offset} to take &Ut1Provider.
- Add Ut1Provider::{iter, as_slice} + IntoIterator for &Ut1Provider.
- Sort records once in from_eop_data; use partition_point (binary search) with fast-path.
- Remove Vec clones/allocs on hot paths → large UT1 conversion speedup.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @FusRoman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the performance and usability of UT1 conversions by transitioning to borrowed Ut1Provider instances, optimizing the UT1 offset lookup to logarithmic time, and improving the efficiency of EOP data parsing. It also introduces new ergonomic iteration helpers for better data access.

Highlights

  • Borrowing Ut1Provider: The Ut1Provider is now passed by reference (&Ut1Provider) instead of by value in UT1 conversion functions (from_ut1_duration, to_ut1_duration, to_ut1). This change eliminates large Vec clones on hot paths, significantly reducing overhead.
  • Optimized UT1 Offset Lookup: The ut1_offset lookup has been optimized from a linear scan to an O(log n) operation using slice::partition_point. A fast-path is also included for queries that are at or after the latest record, further improving performance for common scenarios.
  • Efficient EOP Data Parsing: The Ut1Provider::from_eop_data parser has been refactored to be single-pass, avoid per-line allocations, and conditionally sort the data only if it's detected as out of order. This makes EOP data parsing much more efficient.
  • Ergonomic Iteration Helpers: New ergonomic helpers (iter, as_slice, and IntoIterator for &Ut1Provider) have been added to Ut1Provider, providing zero-copy iteration and direct slice access to the underlying data.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@c0c0688). Learn more about missing BASE report.
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #419   +/-   ##
=========================================
  Coverage          ?   82.67%           
=========================================
  Files             ?       24           
  Lines             ?     3567           
  Branches          ?        0           
=========================================
  Hits              ?     2949           
  Misses            ?      618           
  Partials          ?        0           

☔ 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that brings significant performance improvements to UT1 conversions. The change to borrow Ut1Provider instead of moving it is a great optimization, and the breaking change is well-documented. The new O(log n) lookup in ut1_offset and the single-pass EOP parser are impressive. The code is clean and the new iterator helpers improve the API's ergonomics. I have a couple of minor suggestions to further improve the robustness and conciseness of the EOP parser.

Copy link
Member

@ChristopherRabotin ChristopherRabotin left a comment

Choose a reason for hiding this comment

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

This is excellent, thank you!

Could you implement one of the recommendations by Gemini , and also change the version in the Cargo.toml to 4.2.0? That's just to prevent accidentally releasing this minor breaking change as the next 4.1.x version.

Thank you

@ChristopherRabotin
Copy link
Member

Thanks @FusRoman!

@ChristopherRabotin ChristopherRabotin merged commit aa4e5ae into nyx-space:master Sep 1, 2025
30 checks passed
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.

Perf: Borrow Ut1Provider in UT1 conversions, add O(log n) offset lookup, and speed up EOP parsing

2 participants