Skip to content
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

Report single MissingTree instead of large MissingFieldError[] array for incomplete cache reads #8734

Merged
merged 4 commits into from
Sep 17, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Aug 31, 2021

In the (somewhat pathological but also entirely plausible) example in #8707, more than 60% of cache read time is spent creating MissingFieldError objects, in part because an unnecessary InvariantError is created and then used only for its message; in part because the MissingFieldError class inherits from Error, which makes super(message) initialization expensive; but also (in large part) because there are just so many error objects (tens of thousands).

This pull request needs more work to minimize breaking changes for anyone using the MissingFieldError type directly, but it offers an extremely appealing solution to the performance problems enumerated above: What if we reported only one, combined MissingFieldError per cache read?

On a personal note, I'm leaving for a weeklong vacation today, so I don't need this reviewed any time soon. 🏝

@bgirard
Copy link

bgirard commented Sep 14, 2021

In this comment I confirmed that this PR fixes my issue: #8707 (comment). Thanks again!

@benjamn benjamn force-pushed the issue-8707-MissingFieldError-performance branch from 0125b55 to 4203a8a Compare September 17, 2021 17:06
@@ -241,6 +230,7 @@ export class StoreReader {
};

const rootRef = makeReference(rootId);
const merger = new DeepMerger;
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought TypeScript hated it when you invoke a constructor without parens.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get a comment about why we’re using DeepMerger directly over calling mergeDeep? Is there some kind of stateful thing going on here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes (to both)! b4c9a65

Copy link
Contributor

@brainkim brainkim left a comment

Choose a reason for hiding this comment

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

Looks good!

@benjamn benjamn merged commit 756ab87 into release-3.5 Sep 17, 2021
@benjamn benjamn deleted the issue-8707-MissingFieldError-performance branch September 17, 2021 17:49
benjamn added a commit that referenced this pull request May 19, 2022
Issue #9735 appears to be due to a bug I introduced in my commit
756ab87 in PR #8734.

Premature optimization has a bad reputation already, but you can add
this PR to the mountain of evidence in its disfavor.
benjamn added a commit that referenced this pull request May 19, 2022
Issue #9735 appears to be due to a bug I introduced in my commit
756ab87 in PR #8734.

Premature optimization has a bad reputation already, but you can add
this PR to the mountain of evidence in its disfavor.
benjamn added a commit that referenced this pull request May 23, 2022
Issue #9735 appears to be due to a bug I introduced in my commit
756ab87 in PR #8734.

Premature optimization has a bad reputation already, but you can add
this PR to the mountain of evidence in its disfavor.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants