Skip to content

Add memoized variants of mappers#90

Merged
inducer merged 4 commits intoinducer:mainfrom
kaushikcfd:memoized_mappers
May 3, 2022
Merged

Add memoized variants of mappers#90
inducer merged 4 commits intoinducer:mainfrom
kaushikcfd:memoized_mappers

Conversation

@kaushikcfd
Copy link
Collaborator

Closes #89.

Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

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

Thanks! Sorry this sat so long, it fell through the cracks somehow. A few things below, hopefully straightforward to deal with.

A cache key implementation assuming *expr* is immutable while elements
of *args*, *kwargs* aren't.
"""
return ((id(expr), expr), args, tuple(sorted(kwargs.items())))
Copy link
Owner

Choose a reason for hiding this comment

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

Use immutables for hashing? (but see below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for trying!

@kaushikcfd kaushikcfd force-pushed the memoized_mappers branch 3 times, most recently from f1373c7 to ad51ea5 Compare May 3, 2022 20:26
@kaushikcfd kaushikcfd requested a review from inducer May 3, 2022 20:55
@inducer inducer force-pushed the memoized_mappers branch from c61ff56 to dc96d2a Compare May 3, 2022 22:16
@inducer inducer enabled auto-merge (rebase) May 3, 2022 22:17
@inducer
Copy link
Owner

inducer commented May 3, 2022

LGTM! In it goes. (Some doc tweaks in dc96d2a.)

@inducer inducer merged commit d343cf1 into inducer:main May 3, 2022
Comment on lines +59 to +63
class CachedSubstitutionMapper(CachedIdentityMapper,
SubstitutionMapper):
def __init__(self, subst_func):
CachedIdentityMapper.__init__(self)
SubstitutionMapper.__init__(self, subst_func)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this actually return from the cache for map_variable, map_subscript, map_lookup?

Copy link
Owner

Choose a reason for hiding this comment

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

Why wouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just wondering because the SubstitutionMapper from which this is derived directly calls the IdentityMapper for these methods. But if I understood the MRO here correctly, this appears to not be an issue.

Copy link
Owner

Choose a reason for hiding this comment

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

SubstitutionMapper from which this is derived directly calls the IdentityMapper for these methods.

Cache lookups happen in rec, but SubstitutionMapper doesn't override rec. I think this is OK, but maybe I'm missing something.

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.

Memoizing results of traversals

3 participants