Skip to content

Caching of some frame-static attributes - #7949

Merged
adrn merged 8 commits into
astropy:masterfrom
eteq:cache-frame-class-attrs
Oct 25, 2018
Merged

adrn merged 8 commits into
astropy:masterfrom
eteq:cache-frame-class-attrs

Conversation

@eteq

@eteq eteq commented Oct 23, 2018 •

Copy link
Copy Markdown
Member

This is an incomplete implementation of a potential hot-spot in the SkyCoord initializer. Specifically, the frequent accessing of certain frame-specific attributes that really don't need to be recomputed a lot (see #7030 for some related disucssion).

The first two commit seems to mostly work, except for something I don't fully understand (but can probably figure out how to work around) with SkyOffsetFrames. Combined they seem to give a 50% speedup in certain SkyCoord initialization cases.

However, the last one is more mysterious: that one caches the representation_component_names at a frame-level. I thought this is supposed to be frame-constant for any particular representation (and that is how the cache is implemented), but for some reason it is causing failures all over, I think at least in part due to either the differentials or some of the related changes in representations. @adrn or @mhvk, do you have any idea what might be going on here? To see the failure in question you can grab this branch and do python setup.py test -P coordinates - you get a bunch of similar failures that don't seem to have much obvious in common except that they are related to missing names of representation components...

@eteq eteq added this to the v3.1 milestone Oct 23, 2018
@astropy-bot

astropy-bot Bot commented Oct 23, 2018 •

Copy link
Copy Markdown

Hi there @eteq 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

This is necessary because at any time the user might add new representation or differential classes.  Other pacakges (e.g. Sunpy) use this functionality in the wild so it must be supported.  This change uses a hash of the rep/diff class dictionaries to detect when a change has occurred.
@eteq
eteq force-pushed the cache-frame-class-attrs branch from 33dbe71 to 05f245c Compare October 24, 2018 04:50
@eteq

eteq commented Oct 24, 2018 •

Copy link
Copy Markdown
Member Author

At @astrofrog's suggestion during the Astropy telecon today, this is now a stand-alone PR with just the first part (hence the strikethrough in the description above). I may still try to get the latter parts to work, but better to review piecemeal than try to get it all in at the last minute.

Note that this does now handle SkyOffsetFrames. It also uses some hashing cleverness to detect when new representations are added at runtime.

@eteq
eteq force-pushed the cache-frame-class-attrs branch from 68643b5 to c1db5bb Compare October 24, 2018 04:58
@eteq

eteq commented Oct 24, 2018 •

Copy link
Copy Markdown
Member Author

Note: I tested sunpy against this PR and it works fine. Although the only reason that's true is that a regression test caught an earlier error... a regression test from ~3 yrs ago that @Cadair's usage in Sunpy prompted. Finally the work on regression tests is paying off for @Cadair the Coordinates Canary in a Coal mine! 😉

@eteq
eteq requested review from adrn and mhvk October 24, 2018 21:14
@eteq eteq changed the title WIP: Caching of some frame-static attributes Caching of some frame-static attributes Oct 24, 2018
@eteq

eteq commented Oct 24, 2018

Copy link
Copy Markdown
Member Author

Alright I think this may be good to go now - should be ready for review since the main tests are passing now.

One implementation note: the validity of the cache depends on it being invalidated when the astropy.coordinatesrepresentation.REPRESENTATION_CLASSES and astropy.coordinatesrepresentation.DIFFERENTIAL_CLASSES dictionaries are modified (via the astropy.coordinatesrepresentation._invalidate_reprdiff_cls_hash function). Neither of those classes are supposed to be user-facing. But if someone has been messing with them, they may find this all of a sudden breaks their code if they don't call _invalidate_reprdiff_cls_hash. If there were a dict that could issue callbacks on changes to the dict that would be a bit cleaner, but I gave that a quick try and it seemed a lot messier than the current implementation (mainly because you have to override basically every dict method).

@eteq

eteq commented Oct 24, 2018

Copy link
Copy Markdown
Member Author

Oh and if @StuartLittlefair or @Juanlu001 happen to be available in the next couple days, it might be nice to get an independent pair of eyes on this... (@adrn, @mhvk, and I have been thinking about some of this together for a while now and I'm a bit worried about the groupthink effect)

@adrn adrn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this looks ok. A few very minor comments, but otherwise just acknowledge my weariness about using global and I'll be happy with this :)

Comment thread CHANGES.rst Outdated
Comment thread astropy/coordinates/representation.py
Comment thread astropy/coordinates/representation.py
adrn and others added 2 commits October 25, 2018 11:50
@adrn

adrn commented Oct 25, 2018

Copy link
Copy Markdown
Member

OK sounds good! The build failures are because of Numpy 1.15.3 issues, so merging.

@eerovaher eerovaher mentioned this pull request Feb 1, 2024
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants