Cache the detector layout file in MetisLMSSpectralTraceList to avoid reading the file N*28 times for every OpticalTrain usage - #987
Merged
Conversation
MetisLMSSpectralTrace.fov_grid re-read and re-parsed the detector layout file from disk on every call. During construction of an LMS trace list it is called several times for each of the 28 slices (once per trace at construction, again through update_meta), so the same small file was read dozens of times. Wrap the read in a small lru_cache'd module function. Adds a test that the file is read only once for repeated calls.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #987 +/- ##
==========================================
+ Coverage 76.45% 76.46% +0.01%
==========================================
Files 69 69
Lines 9021 9025 +4
==========================================
+ Hits 6897 6901 +4
Misses 2124 2124 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MetisLMSSpectralTraceList to avoid reading the file N*28 times for every OpticalTrain usage
astronomyk
marked this pull request as ready for review
August 24, 2026 14:10
teutoburg
approved these changes
Aug 24, 2026
teutoburg
left a comment
Contributor
There was a problem hiding this comment.
This shouldn't hurt I guess. Now stop playing with the toaster and go back to being a manager 😜
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL;DR - tiny efficiency speed up to avoid excessive disk reads of the DetectorLayout file
@teutoburg requesting your review for this one as it's more about ScopeSim mehcanics, rather than METIS mechanics
What
MetisLMSSpectralTrace.fov_gridneeds the detector limits and read + parsed the layout file (!DET.layout.file_name) from disk on every call. Building an LMS trace list calls it several times for each of the 28 slices (trace construction,update_meta, volume setup), so the same small file was read dozens of times perOpticalTrain— more duringobserve().The read is wrapped in a small
lru_cache'd module function (maxsize=8, keyed on the filename), so each layout file is read once per session.Testing
TestDetectorLayoutCache::test_layout_file_is_read_only_oncecounts the actualascii.readcalls for repeated lookups.