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.
This pull introduces/changes:
Responses::HTTP
)Given:
(:Person)-[:WROTE]->(:Article)
(with 1:N relationships)When I run the following query:
I get a different instance of
Person
for everyArticle
in the result set. It's reasonable to assume we can return the same instance for all references to the same node in the same result. This PR is a proof of concept for that in the hopes that I didn't overlook any context behind yielding new instances each time. :-) Additional benefits include saving a bit of RAM and probably some CPU time since we can skip the conversion from hash toActiveNode
/ActiveRel
on subsequent occurrences of the same node in the result.I didn't test whether nodes/rels in paths would use the cached instances, but if not, maybe that's a relatively simple change? I mainly wanted to get thoughts on this before I waded in too deep. :-)
Identity maps can be gross because cache invalidation is hard, but the scope of caching here is pretty small. It only sits at the response level, so it'll be thrown away with the response and subsequent queries will return fresh instances. Per-query identity seems like a reasonable compromise between performance and flipping tables over frustration caused by cache-invalidation bugs.
Pings:
@cheerfulstoic
@subvertallchris