-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Cache match elements to speed up compiler #1831
Conversation
Btw, won't the caching break matching of interpolated selectors? I guess the "element expansion" should only be cached when selector contains no |
continue; | ||
} | ||
|
||
if( typeof v.value.value !== "string" ){ |
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.
This make sense. But unfortunately there're too many possible value types beyond a string (e.g. an array, an expression etc.) so it still remains broken for "complex" variable values... Ideally we should use element.genCSS()
instead of simple element.value
expansion for interpolated things everywhere.
I was also thinking of something like that (i.e. caching + proper @{var}
expansion) but I thought it would make sense to fix #1196 first which means this whole thing to be completely rewritten from scratch (because we will need to switch from the "element by element" to a "string/substring" matching method or a sort of).
I looked into that as well but decided to go with this for a two reasons.
oelements = other.elements.map( function(v) {
return v.combinator.value + (v.value.value || v.value);
}).join("").match(/[,&#\.\w-]([\w-]|(\\.))*/g);
.class[a=1]{
...
}
Just checked and this compiles correctly: @var: one;
.mixin-@{var}{
width:10;
}
.test{
.mixin-one;
} |
Yes. I mean situations like this:
I.e. the test for "string" type does not really improve anything.
I meant more tricky situations where the value of a variable used in selector changes in between mixin calls. Well, I did some testing and it seems that for the moment there's no way to achive anything like that, so indeed caching can't break anything. A code to illustrate what I mean:
There
Sorry, wrong issue number, I meant #1270 and similar, i.e.:
|
Either way the performance improvement seems to be quite noticeable (it's 10-15% improvement for the less.benchmark which does not use too many mixin calls, so it should be even faster for things like Bootstrap). So personally I sympathize merging this. |
if( !this._elements ){ | ||
|
||
len = this.elements.length; | ||
for(i = 0; i < len; i++){ |
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.
Btw, var i
is not declared here (so grunt test fails).
okay then, merged |
No description provided.