-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX links] relationship setup for link fetch should batch #6586
Conversation
Would you mind fleshing out the PR description a bit more? It is unclear what the overall goal here is, what this PR is doing, etc... |
@sly7-7 - Would you mind retesting against your app (with the changes @runspired just pushed up)? |
@rwjblue Of course, I'm just a bit disapointed I can't do it now. But I will try that pr as soon as I arrive at work tomorrow morning. I have a case which took about 3 minutes for the relationships to load. |
Awesome, thank you! |
@rwjblue From my "benchmark" (the load handler violation reported by chrome), loading 5750 relations went from an average of 3 minutes to 850ms. So it's a big win here, I would say for me 200x faster. Compared to ED 3.4 (~250ms) it remains slower though. |
I suspect based on numbers you shared previously it might be closer to a wash (more up front cost, less cost on access by the ui), but if not the case then this is more evidence of the need for the perf work scoped in #6573 |
* [BUGFIX links] relationship setup for link fetch should batch * fix lint * remove unnecessary things * utilize a single store._push to avoid double flushing relationship changes
* [BUGFIX links] relationship setup for link fetch should batch * fix lint * remove unnecessary things * utilize a single store._push to avoid double flushing relationship changes
* [BUGFIX links] relationship setup for link fetch should batch * fix lint * remove unnecessary things * utilize a single store._push to avoid double flushing relationship changes
* [BUGFIX links] relationship setup for link fetch should batch * fix lint * remove unnecessary things * utilize a single store._push to avoid double flushing relationship changes
* [BUGFIX links] relationship setup for link fetch should batch * fix lint * remove unnecessary things * utilize a single store._push to avoid double flushing relationship changes
@sly7-7 this is good stuff. I haven't dug deep but this MR broke our (relatively large) app and I'm wondering if this is off spec a little. We're following the I think there are 2 problems with this:
Here are the work-arounds we've messed with so far:
I know we're a bit late to the game here (just updating to 3.16 release currently). Maybe it's already been addressed and we just need to bump a version of ED? Thanks! |
Looking at the code more closely the same issue likely applies to |
I got confirmation that these 2 lines are indeed the issue: https://github.com/emberjs/data/pull/6586/files#diff-9b9bb6244a381112cef76850226d8072R138-R139 Again, it's request-level vs model-level data IMO. |
@travisghansen your finding is correct but this is also intentional. The spec is a bit of a grey area here. When you fetch a relationship by link, the links in the document level of the response are the same as the links within a relationship object. So while yes we are moving links from document to resource level, this is allowable in this case. Where the spec is grey is that the spec allows you to leave off the |
@runspired thanks for the response! Let me digest this for a bit with the team and provide a response. |
**Description By @runspired **
Most new data enters the cache via
store._push
which ensures that all operations on state internally occur within one ED runloop. An exception is when fetching relationships via links, where in addition to calling_push
we make a call tointernalModel.linkWasLoadedForRelationship
. Since this call is not within the call to_push
we were accidentally spinning up thousands of run loops for hasMany relationships.Here we ensure that this loading always has an outer run loop so that scheduled work is appropriately batched internally.
EDIT
After reflection, @runspired realized that the call to
linkWasLoadedForRelationship
was especially odd. After digging it, it became apparent that this was only necessary to forward links and meta to the relationship, for which we already have a codepath in_push
when we syncRelationshipDataForLinks to fix the payload. We are able to remove this secondary "push" codepath entirely, which also means we further improve the performance of this codepath by not pushing twice.The application that @sly7-7 demo'd this perf issue with went from ~12s to <600ms with the original batching change. I suspect if he re-profiles we will now be <250ms.
Edit 2
After making the previous change to eliminate
linkWasLoadedForRelationship
, @runspired realized that while we eliminated one relationship flush, we are still callingstore._push
twice meaning we still flush relationship changes twice when we only need one flush. A new commit has been added that changes our relationship sync logic in away to allow us to only flush once. He looks forward to seeing what the new performance number is :)