-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Optimize performance by optionally collectiong only EA directives #14850
Conversation
ab35cc9
to
18ef9f1
Compare
This seems like a pretty good idea since just about every Angular app I have ever written doesn't actually use comment or CSS class based directives. We could even make this opt-out in a future version... The API naming seems a bit clunky though... Perhaps something more like |
I also like it. One of these things that are really obvious in hindsight. |
Good! |
18ef9f1
to
e40345e
Compare
I have updated it. The function name is Because:
I force to have at least |
Great and rapid work - thanks @drpicox Can we have a quick chat about what might work best before you make any more changes... Perhaps we could make it explicit, following the getter/setter style of
or perhaps we could disable them together...
or some better thing?? |
I have seen some people using class directives, mainly because some people work like times of backbone or jquey and they use templates from designers which do thinks like So it make sense to have separated class and comments. I have never seen a comment directive. I know why it is supposed to be useful because of the angular documentation. I have difficult to do a chat by now, now I'm at AngularCamp listening to @toddmotto talking about .component :) |
Btw I'm follows you at Twitter, so if you follow me you can send me pms and have the chat. |
@@ -3128,17 +3128,129 @@ describe('$compile', function() { | |||
}); | |||
}); | |||
|
|||
it('should observe interpolated attrs', inject(function($rootScope, $compile) { |
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.
Why was this test removed?
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.
Ops! It shouldn't!
I think the explicit version is the way to go. It's verbose, but you are not gonna use this more than once per app, and it also doesn't give the impression that you can disable EA
|
$rootScope = _$rootScope_; | ||
})); | ||
|
||
it('should not compile class directives', function() { |
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.
I think it would be cleaner to use test-collect
for all testcases. It makes the comparison easier.
Yeah, 👍 for the explicit versions from me too. BTW, I would feel more confident about the tests, if we used the they('should handle comment directives appropriately ($prop)', [
{restrict: 'EA', collect: false},
{restrict: 'EAC', collect: false},
{restrict: 'EAM', collect: true},
{restrict: 'EACM', collect: true}
], function(config) {
module(function($compileProvider) {
$compileProvider.restrictDirectivesTo(config.restrict);
});
inject(function() {
var html = '<!-- directive: test-collect -->';
element = $compile('<div>' + html + '</div>')($rootScope);
expect(collected).toBe(config.collect);
});
}); |
expect(collected).toBe(true); | ||
})); | ||
|
||
angular.forEach([ |
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.
You don't need angular.
.
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.
Ops, true! Thanks!
Do we have any (verifiable) numbers on how performance is affected by this? I also think it is a good idea to mention this in the Running in Production section of the Developer Guide. |
I did my performance benchmarks using code from my customers (just right click and get source). |
699ab98
to
af12104
Compare
I have added a benchpress benchmark.
How to run?
The numbers that I have obtained are:
|
af12104
to
dd07d9c
Compare
dd07d9c
to
4bde767
Compare
* $compileProvider.commentDirectivesEnabled(false); | ||
* ``` | ||
* | ||
* @param {boolean} false if the compiler may ignore directives on comments |
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.
You should have the argument name right after the type. Now false
is interpreted as the argument type and the rest as the description.
Thanks @gkalpak for comments, I have updated it. |
2fa432f
to
af05406
Compare
af05406
to
66f2eaa
Compare
LGTM |
…ass and comment directives When the functions `cssClassDirectivesEnabled()` / `commentDirectivesEnabled()` on the `$compileProvider` are called with `false`, then the compiler won't look for directives on css classes / comment elements. This can result in a compilation speed-up of around 10%. PR (#14850)
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...) Performance optimization that introduces a new feature as
$compileProvider
configuration.What is the current behavior? (You can also link to an open issue here):
$compile
collect directives from entities, attributes, classes and comments. It parses all four kind of directives, although usually only E (components) and A ("directives") are used in most of the projects.What is the new behavior (if this is a feature change)?: It introduces a new configuration in the
$compileProvider
that disables the compilation of C and M directives:Does this PR introduce a breaking change?
No. By default is configured true, thus it is compatible with all existing code.
Please check if the PR fulfills these requirements
Other information:
It is closely related to #14848
I have reused the same benchmarks to measure the improved performance of this PR, and it is around 10-15% of performance improvement by setting restrictDirectivesTo to 'EA'.