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

DM-46581: Speed up TimeConverter #1090

Merged
merged 7 commits into from
Oct 4, 2024
Merged

DM-46581: Speed up TimeConverter #1090

merged 7 commits into from
Oct 4, 2024

Conversation

timj
Copy link
Member

@timj timj commented Oct 2, 2024

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes
  • (if changing dimensions.yaml) make a copy of dimensions.yaml in configs/old_dimensions

@timj
Copy link
Member Author

timj commented Oct 2, 2024

This change almost halves the time of nsec_to_astropy (and makes astropy_to_nsec 4% faster).

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 6 lines in your changes missing coverage. Please review.

Project coverage is 89.69%. Comparing base (e90bb0f) to head (b6329fd).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
python/lsst/daf/butler/time_utils.py 85.18% 2 Missing and 2 partials ⚠️
python/lsst/daf/butler/_timespan.py 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1090      +/-   ##
==========================================
- Coverage   89.69%   89.69%   -0.01%     
==========================================
  Files         361      361              
  Lines       47278    47306      +28     
  Branches     9716     9720       +4     
==========================================
+ Hits        42407    42429      +22     
- Misses       3495     3498       +3     
- Partials     1376     1379       +3     

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

@timj timj force-pushed the tickets/DM-46581 branch from 3e01c5e to 1d04c21 Compare October 3, 2024 21:37
timj and others added 6 commits October 3, 2024 15:06
Include the jd1 and jd2 to ensure that we can recreate
the time accurately enough from the repr() form.
Constructing the TimeDelta is slow. Calculating the JD components
and explicitly adding them to the epoch JD values is much faster
than constructing a TimeDelta and adding that to a Time.
This format is only ever use by TimeConverter so we can trust that
the values passed are always OK and skip usual checks.
We would like to get microseconds in our ISO output form.
We only use it in a couple of places explicitly but it is
used.
@timj timj force-pushed the tickets/DM-46581 branch from 1d04c21 to c21bbc1 Compare October 3, 2024 22:06
# For JD times we want to use jd1 and jd2 to maintain precision.
if isinstance(t, astropy.time.Time):
if t.format == "jd":
return f"astropy.time.Time({t.jd1}, {t.jd2}, scale='{t.scale}', format='{t.format}')"
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't trigger with the new code because for Timespan we always convert the Time to nsec internally and then convert back to Time on request and so return a format=unix_tai_fast variant for repr. If we ever decide to simply keep the Timespan we were given then this would trigger again.

We have decided that returning it in tai unix fast format is
going to be confusing since these times are visible to people
via Timespan. Therefore switch the format to "jd" and accept
a small overhead going from 8us to 10us in construction.
@timj timj merged commit 9600402 into main Oct 4, 2024
17 of 18 checks passed
@timj timj deleted the tickets/DM-46581 branch October 4, 2024 14:09
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.

2 participants