Improve performance of bad_times and mask_times #123
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes a performance issue note on Slack in #thermal_working_group:
I am doing some work that requires me to run the thermal models many, many times in a row, and was profiling my code when I noticed that the pm2thv1t model is running significantly slower than the pm1thv2t model, e.g. in my MATLAB setup:
This PR vectorizes the bad times processing and minimizes the number of date --> time (CXC second) conversions. It also factors this processing out into a separate function (working to improve separation in this code).
Some points of note:
bad_times
in a JSON model spec file are in standard Year-day-of-year date format. There was another part of the code already making this assumption so I think this is OK but this needs review.mask_*
attributes. Previously these values were set corresponding to everybad_times
interval in the spec file, including those that are outside of the model date range. While this was not a problem per se it was likely impacting performance. See the functional testing section for more.Interface impacts
None.
Testing
Unit tests
Independent check of unit tests by [REVIEWER NAME]
Functional tests
I ran this script on master (version 4.26.1) and this branch (4.27.1.dev1+g19aed41).
Master version 4.26.1
Dev version 4.27.1.dev1+g19aed41