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

[BUGFIX lts] Fix tag cycles in query parameters #19138

Merged
merged 1 commit into from
Sep 30, 2020

Conversation

pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Sep 14, 2020

Currently, we wrap query parameters with @dependentKeyCompat manually
to ensure they work with the legacy router setup, which watches QPs
using observers. When a QP value is labeled as @tracked, we don't need
to replace it with @dependentKeyCompat, but since it's just a plain
native getter (from the decorator) we do anyways. This results in a tag
cycle being created, which can result in a negative performance impact,
as every render pass will be invalidated by the cycle and require a
subsequent full revalidation.

This bug would have been caught by our ALLOW_CYCLES logic, but that
logic was faulty - it was allowing too many cycles, anything that was
accessed via get. It should only have allowed cycles from computeds
themselves.

This PR fixes the bug with ALLOW_CYCLES, and the subsequent bug with
@tracked by only wrapping with @dependentKeyCompat if the value is
not @tracked. It also adds an assertion to prevent users from using
@dependentKeyCompat with @computed or @tracked.

Verified that the test failed after fixing ALLOW_CYCLES, and passed
again after the fix.

@pzuraq pzuraq force-pushed the bugfix/fix-tag-cycles-in-query-params branch from f782179 to 2a73dd3 Compare September 14, 2020 18:13
@rwjblue
Copy link
Member

rwjblue commented Sep 14, 2020

@pzuraq - Can you review the open issues RE: QP + cycles, and cross link the ones this fixes?

@chancancode
Copy link
Member

🙌 #18981

@chancancode
Copy link
Member

We should probably add a QP test for this?

@rwjblue
Copy link
Member

rwjblue commented Sep 14, 2020

We should probably add a QP test for this?

Yes, absolutely. That was why I was hoping we could cross link the related issues, and create test cases for them...

@chancancode
Copy link
Member

I think I have a small repro in twiddle, but maybe not small enough for a test case

@pzuraq pzuraq force-pushed the bugfix/fix-tag-cycles-in-query-params branch from 2a73dd3 to 6659046 Compare September 14, 2020 19:59
@pzuraq
Copy link
Contributor Author

pzuraq commented Sep 14, 2020

Note that there was already a test case, which was passing mistakenly due to the ALLOW_CYCLES logic being faulty. Fixing that logic caused the test to fail, and then the rest of the PR fixed it. Noted this in the original PR description.

@rwjblue did link me to a twiddle with an additional failure that somehow was caused by using the {{log}} helper, I added that as a test case as well.

@pzuraq pzuraq force-pushed the bugfix/fix-tag-cycles-in-query-params branch from 6659046 to aa7fa88 Compare September 14, 2020 20:32
@pzuraq pzuraq force-pushed the bugfix/fix-tag-cycles-in-query-params branch from aa7fa88 to 1508fce Compare September 28, 2020 22:49
Currently, we wrap query parameters with @dependentKeyCompat manually
to ensure they work with the legacy router setup, which watches QPs
using observers. When a QP value is labeled as @Tracked, we don't need
to replace it with @dependentKeyCompat, but since it's just a plain
native getter (from the decorator) we do anyways. This results in a tag
cycle being created, which can result in a negative performance impact,
as every render pass will be invalidated by the cycle and require a
subsequent full revalidation.

This bug would have been caught by our ALLOW_CYCLES logic, but that
logic was faulty - it was allowing too many cycles, anything that was
accessed via get. It should only have allowed cycles from computeds
themselves.

This PR fixes the bug with ALLOW_CYCLES, and the subsequent bug with
@Tracked by only wrapping with @dependentKeyCompat if the value is
not @Tracked. It also adds an assertion to prevent users from using
@dependentKeyCompat with @computed or @Tracked.

Verified that the test failed after fixing ALLOW_CYCLES, and passed
again after the fix.
@rwjblue rwjblue force-pushed the bugfix/fix-tag-cycles-in-query-params branch from 1508fce to 57a2044 Compare September 30, 2020 14:20
Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Rebased on top of all the prettier/eslint changes that just landed on master, and fixed up the error message issue that @chriskrycho pointed out.

Should be good to land once CI is happy...

packages/@ember/object/compat.ts Outdated Show resolved Hide resolved
@rwjblue rwjblue merged commit 06af1df into master Sep 30, 2020
@rwjblue rwjblue deleted the bugfix/fix-tag-cycles-in-query-params branch September 30, 2020 14:36
pzuraq pushed a commit that referenced this pull request Oct 1, 2020
The bugfix for disallowed cycles in tracked props in #19138 attempted
to also narrow the number of cycles that are allowed in general. Cycles
should only be allowed for computed property deps, for legacy support
reasons. The logic to allow cycles for these tags in particular was
mistakenly added to `setup`, which runs on the _prototype_ of the class.
This meant that _instance_ computed props were not allowed to have
cycles, and this was causing failures in the ecosystem.

Added a test that failed and is fixed with this change. I also attempted
to create a cycle with `@alias` since it uses a different
implementation, but I wasn't able to create one which didn't result in
a Maximum Callstack style recursion error, so I think it's just not
possible at all anyways, since `@alias` is eager always and never
caches.
pzuraq pushed a commit that referenced this pull request Oct 1, 2020
The bugfix for disallowed cycles in tracked props in #19138 attempted
to also narrow the number of cycles that are allowed in general. Cycles
should only be allowed for computed property deps, for legacy support
reasons. The logic to allow cycles for these tags in particular was
mistakenly added to `setup`, which runs on the _prototype_ of the class.
This meant that _instance_ computed props were not allowed to have
cycles, and this was causing failures in the ecosystem.

Added a test that failed and is fixed with this change. I also attempted
to create a cycle with `@alias` since it uses a different
implementation, but I wasn't able to create one which didn't result in
a Maximum Callstack style recursion error, so I think it's just not
possible at all anyways, since `@alias` is eager always and never
caches.
@Samsinite
Copy link

Samsinite commented Oct 7, 2020

Does this fix the performance issue that was present when some query params were used alongside tracked properties?

rwjblue pushed a commit that referenced this pull request Nov 10, 2020
The bugfix for disallowed cycles in tracked props in #19138 attempted
to also narrow the number of cycles that are allowed in general. Cycles
should only be allowed for computed property deps, for legacy support
reasons. The logic to allow cycles for these tags in particular was
mistakenly added to `setup`, which runs on the _prototype_ of the class.
This meant that _instance_ computed props were not allowed to have
cycles, and this was causing failures in the ecosystem.

Added a test that failed and is fixed with this change. I also attempted
to create a cycle with `@alias` since it uses a different
implementation, but I wasn't able to create one which didn't result in
a Maximum Callstack style recursion error, so I think it's just not
possible at all anyways, since `@alias` is eager always and never
caches.

(cherry picked from commit b612d47)
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.

5 participants