Cache tracing of footprint outlines - #209
Conversation
Tracing region outlines out of a HEALPix footprint takes a couple of seconds, and is repeated in full every time a map is built, even though a process may build many maps from one shared footprint. Split the tracing into _trace_footprint_outlines, cached on the contents of the footprint. The footprint is keyed as bytes because an ndarray is unhashable, and so cannot be an argument to a cached function; the round trip through bytes costs a fraction of a millisecond against the seconds it saves. _compute_footprint_outlines returns a copy, so that a caller that modifies the outlines it gets back cannot corrupt the cached value.
21ca212 to
cf66158
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
==========================================
+ Coverage 67.49% 71.94% +4.45%
==========================================
Files 54 147 +93
Lines 4104 10388 +6284
Branches 576 1115 +539
==========================================
+ Hits 2770 7474 +4704
- Misses 1097 2416 +1319
- Partials 237 498 +261 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| footprint_outline = footprint_outline.drop(tiny_loops) | ||
| return footprint_outline | ||
|
|
||
| @staticmethod |
There was a problem hiding this comment.
This is being really picky and more about best practices than something I actually think makes a difference here, but this should probably be a class method rather that a static method, and then you can use the passed class instead of VisitMapBuilder by name. That way, subclasses can replace _trace_footprint_outlines if they need to.
ehneilsen
left a comment
There was a problem hiding this comment.
There's one minor suggestion (in a comment), but I don't think it's important enough to block merging.
|
@nemovc you are cleared to merge this PR, unless you want to address Eric's comment above about @staticmethod vs. class method. |
Tracing region outlines out of a HEALPix footprint takes a couple of seconds, and is repeated in full every time a map is built, even though a process may build many maps from one shared footprint.
Split the tracing into _trace_footprint_outlines, cached on the contents of the footprint. The footprint is keyed as bytes because an ndarray is unhashable, and so cannot be an argument to a cached function; the round trip through bytes costs a fraction of a millisecond against the seconds it saves. _compute_footprint_outlines returns a copy, so that a caller that modifies the outlines it gets back cannot corrupt the cached value.