-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Very long parse time for simple template #44
Comments
Can confirm - your repo takes me 90 seconds to compile in dev mode & 9 in release mode. I don't know if parser itself can be optimized, but something like this will help (it's not implemented yet). |
I've looked into this some more and it looks like a general problem with the expr_prec_layer macro in the parser. Every call to expr_any ends up in 512 calls to expr_filtered. This is usually not a big issue but in my case when I have two levels of method calls this grows quadratically. I created some test cases and benchmarks during my investigation that can be found here Entering the expr_prec_layer chain in different places gives huge differences. |
This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that more expressions with multiple operators couldn't be parsed. This is handled by using expr_any for right instead only using higher level precedence layers.
This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that expressions with multiple operators couldn't be parsed, for example {{1 * 2 * 3}}. This is handled by using expr_any for right instead only using higher level precedence layers.
This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that expressions with multiple operators couldn't be parsed, for example {{1 * 2 * 3}}. This is handled by using expr_any for the right operand instead of only using higher level precedence layers.
This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that expressions with multiple operators couldn't be parsed, for example {{1 * 2 * 3}}. This is handled by using expr_any for the right operand instead of only using higher level precedence layers.
This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that expressions with multiple operators couldn't be parsed, for example {{1 * 2 * 3}}. This is handled by using expr_any for the right operand instead of only using higher level precedence layers.
I've been using Askama for while and I think it's great.
However I've found one case where some of my templates take a very long time to compile. Now when I finally took some time to investigate it seems to be related to a specific construct in the templates that leads to very long time spent in the parser.
Compilation of the following code takes about a minute for me to compile before it fails.
Profiling of similar case using 0.3.4 shows that most of the time is spent in the parser.
The text was updated successfully, but these errors were encountered: