-
Notifications
You must be signed in to change notification settings - Fork 27.5k
refactor($interpolate): optimize watched $interpolate functions performance #4556
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@@ -10,7 +10,7 @@ describe('$interpolate', function() { | |||
|
|||
it('should return undefined when there are no bindings and textOnly is set to true', | |||
inject(function($interpolate) { | |||
expect($interpolate('some text', true)).toBeUndefined(); | |||
expect($interpolate('some text', true)).toBeNull(); |
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.
For the curious:
The docs say it should return null, but now it returns undefined.
I changed the code instead of changing the docs since returning null
made more sense IMHO.
I'm not sure if adding a Breaking Change note is necessary. I would imagine people testing if the returnValue of $interpolate
is truthy (or is a function), instead of explicitly checking if it's undefined
, specially since the docs say it should return null
.
thanks for the PR. I scheduled this PR to be reviewed and merged for v1.2.1. |
ok, no problem 👍 Just as a side-note (something I thought of yesterday): the addition of |
I rebased against master, and fixed a bug that I didn't catch in my initial PR (which also made the code a bit cleaner). Here's the new jsperf http://jsperf.com/ng-interpolation-optimization/8 If there's any issues or questions with my changes, don't hesitate to add a comment! |
+1 |
1 similar comment
+1 |
@rodyhaddad please take a look at https://github.com/IgorMinar/angular.js/tree/pr-4556 I left a commit there for you that I created during code review of this change. I think that this change is heading in the right direction but there are some major flaws: 1/ the benchmark doesn't take into consideration DOM operations and this change increases the number of DOM writes from 1 per interpolated string to n-times per interpolated string (where n is the number of interpolations in the string). I suspect that because of this, this change will actually make angular slower not faster. This is however fixable. you could just keep track of which parts have been dirty-checked and only the last part should trigger the watch action (which usually is the write). 2/ I also feel that the way the watching is set up is wrong. Why can't I'm going to move this to 1.2.7 and if you can get these issues fixed, I'll be happy to review them again. Please don't squash the changes in this PR, complex PRs like this one are easier to review if the iterative changes are not squashed. I'll squash everything before merging to master. |
which is point angular#1 in this PR comment angular#4556 (comment) also merged Igor's first code review IgorMinar@784dd4e
which is point angular#1 in this PR comment angular#4556 (comment) also merged Igor's first code review IgorMinar@784dd4e
@IgorMinar thx for the reply :)
um, no, it doesn't DOM writes happen in the I've had the same concern as you as I was writing this PR.
I solve this stuff with If I'm missing anything, a flaw you saw that my code doesn't cover, writing a failing test would be the most beneficial
It's a design choice. I can imagine someone providing a module that overwrites I can image $$beWatched be used for something like bindonce, or for translations.
I'm guessing performance is the issue here? an extra |
note to myself: punted from ~1.2.6 - I need to get to this this week |
@IgorMinar I'm often connected on the #angularjs irc channel during the day, so don't hesitate to message me if you have any questions/concerns about this PR that pop up and want a quick reply |
note to myself: gah! another punt |
@rodyhaddad thanks, I'll do it. it might need to wait until after ng-conf. this is a significant change and I don't want to break stuff before the conference ;-) In the meantime, @caitp can you also please take a look at this one? |
No problem, no need to rush, I already got my |
and make the first test a bit stricter
not sure how I missed that
Hi Rody, We thought about this a lot and decided not to merge this PR after all. The solution we do want is already implemented in AngularDart: https://github.com/angular/angular.dart/blob/4bf9447cc64650d6c73b66c844fb5396b4a2ae27/lib/core/scope.dart#L278 Would you be interested in implementing that instead? We'd like to have that in v1.3. |
Sounds good, I'll try to have the new PR as soon as possible 👍 |
This PR improves the performance of watched $interpolate functions: http://jsperf.com/ng-interpolation-optimization/8
This is the related Google groups thread, I explain my PR there: https://groups.google.com/forum/#!msg/angular-dev/QmcwYVkfsbo/8Y_pMsal0kYJ
If any changes are unclear, point them out and I'd be happy to elaborate on them :)
Signed the CLA as Rodric Haddad