angular / angular-hint

run-time hinting for AngularJS applications
363 stars 45 forks source link

fix(scopes): correctly meassure perf impact of one-time expressions #124

Closed gkalpak closed 7 years ago

gkalpak commented 7 years ago

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 $watcher). 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

gkalpak commented 7 years ago

@petebacondarwin, PTAL.