Skip to content

Implement Op Lookup Caching#15

Merged
ctrueden merged 5 commits into
masterfrom
scijava/scijava-ops/op-caching
Jul 21, 2020
Merged

Implement Op Lookup Caching#15
ctrueden merged 5 commits into
masterfrom
scijava/scijava-ops/op-caching

Conversation

@gselzer

@gselzer gselzer commented Jun 30, 2020

Copy link
Copy Markdown
Member

This PR implements a basic caching mechanism for storing the Objects returned by Op lookups. The underlying data structure is a Map<OpRef, Object>, where the Object is the Op returned by the matcher when findOpInstance was called with the corresponding OpRef.

TODO:

  • Consider size impact of cache. This cache could get rather large, considering the infinite potential of OpRefs. If not we would have to decide on a caching strategy and cache size: I think LRU makes sense, but we would have to implement a signal that tells the matcher whether or not to cache (and at that point, we might as well just implement Allow user to pass hints when calling Ops scijava#43). Otherwise OpDependency OpRefs will take over the cache.
  • Affirm that the changes within OpRef.equals(), OpRef.hashCode() are correct. This probably depends on decisions made within Document equality/equivalence semantics scijava#36
  • Unit tests. Not sure how this can be tested. Maybe we could assert that the objects returned from two separate calls are equal, and are not if we tell the matcher not to cache (assuming Allow user to pass hints when calling Ops scijava#43 precedes this work)?

I did spend a little time thinking about scijava/scijava#5, but I do not think that it belongs with this work. The matcher knows nothing about the Objects themselves during matching, so this is not the place to insert that kind of behavior.

Closes scijava/scijava#33

gselzer added 5 commits June 30, 2020 10:47
This lines up better with expectation. It is otherwise impossible for a
user to create two equal (equivalent? See scijava/scijava#36)
OpRefs, even if they pass the exact same Objects to the matcher
This ensures that the hashCode is generated using each element of the
types and args arrays and not using the array objects themselves. This
ensures that two OpRefs that are considered "equal" (using
ref1.equals(ref2)) will have the same hash code
This test ensures that OpDependencies are also added to the cache.

This commit also extracts some of the logic to helper methods to reduce
code duplication
@gselzer gselzer marked this pull request as ready for review July 8, 2020 17:53
@gselzer gselzer requested a review from ctrueden July 8, 2020 17:53
@ctrueden ctrueden merged commit cb6a158 into master Jul 21, 2020
@ctrueden ctrueden deleted the scijava/scijava-ops/op-caching branch July 21, 2020 17:44
@ctrueden

Copy link
Copy Markdown
Member

@gselzer Thanks!

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.

Cache op lookups

2 participants