This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
fix(scopes): correctly meassure perf impact of one-time expressions #124
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, one-time expressions were supposed to not trigger perf timers. There were a couple of issues with the implementation: 1. One-time expressions were not detected as such if there was whitespace before the `::`. 2. It depended on internal AngularJS implementation details in a way that would fail to identify certain usecases (e.g. multiple interpolations in a single attribute value or node text). 3. Time spent on the initial evaluation of the one-time expressions would not be accounted for, but could still impact the duration of the first `$digest`. 4. While it is not common, there are cases were one-time expressions don't settle immediately. In such cases, their impact on the `$digest` should not be ignored. This commit fixes the above issues by ensuring that only the "final" call to `$watch` is intercepted (in contrast to intermediate calls that might call a `$$watchDelegate`, which will then create the actual `$watch`er). One-time expressions are intercepted normally and stop triggering perf times as soon as their `unwatch` function is called. Although the dependency on internal AngularJS implementation details could not be avoided, the new implementation is a little more robust, as it relies on fewer and less brittle details :D Fixes angular#109 Closes angular#122
test/scopes.spec.js
Outdated
scope.$apply('c.d = "foo"'); | ||
expect(calls.count()).toBe(1); | ||
expect(countWatchEventsFor(0)).toBe(6); // Change: 2 loops | ||
expect(reactions).toEqual([2, 2, 2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth a comment here, indicating that this is the first time the one time bindings have a value, which is why the reactions are called for a second time.
test/scopes.spec.js
Outdated
'<span>{{::c.d}}</span>' + | ||
'<span>{{ ::c.d }}</span>' + | ||
'<span>{{ :: c.d }}</span>' + | ||
'<span>{{::c.d}}{{ ::c.d }}{{ :: c.d }}</span>' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it useful to check these for non-interpolation bindings such as ng-if
as well?
petebacondarwin
approved these changes
Mar 30, 2017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two minor suggestions
@petebacondarwin, PTAL. |
petebacondarwin
approved these changes
Mar 30, 2017
gkalpak
added a commit
that referenced
this pull request
Mar 30, 2017
Previously, one-time expressions were supposed to not trigger perf timers. There were a couple of issues with the implementation: 1. One-time expressions were not detected as such if there was whitespace before the `::`. 2. It depended on internal AngularJS implementation details in a way that would fail to identify certain usecases (e.g. multiple interpolations in a single attribute value or node text). 3. Time spent on the initial evaluation of the one-time expressions would not be accounted for, but could still impact the duration of the first `$digest`. 4. While it is not common, there are cases were one-time expressions don't settle immediately. In such cases, their impact on the `$digest` should not be ignored. This commit fixes the above issues by ensuring that only the "final" call to `$watch` is intercepted (in contrast to intermediate calls that might call a `$$watchDelegate`, which will then create the actual `$watch`er). One-time expressions are intercepted normally and stop triggering perf times as soon as their `unwatch` function is called. Although the dependency on internal AngularJS implementation details could not be avoided, the new implementation is a little more robust, as it relies on fewer and less brittle details :D Fixes #109 Closes #122 Closes #124
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Previously, one-time expressions were supposed to not trigger perf timers. There
were a couple of issues with the implementation:
the
::
.fail to identify certain usecases (e.g. multiple interpolations in a single
attribute value or node text).
accounted for, but could still impact the duration of the first
$digest
.settle immediately. In such cases, their impact on the
$digest
should notbe ignored.
This commit fixes the above issues by ensuring that only the "final" call to
$watch
is intercepted (in contrast to intermediate calls that might call a$$watchDelegate
, which will then create the actual$watch
er). One-timeexpressions are intercepted normally and stop triggering perf times as soon as
their
unwatch
function is called.Although the dependency on internal AngularJS implementation details could not
be avoided, the new implementation is a little more robust, as it relies on
fewer and less brittle details :D
Fixes #109
Closes #122