-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Parse paths and identifiers only once #840
Conversation
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.
Nice! Did you benchmark the effect?
askama_derive/src/parser/mod.rs
Outdated
|
||
// If `identifier()` fails then just return the original error | ||
Err(err) | ||
(None, name, []) if !name.contains(char::is_uppercase) => { |
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.
What tests break if we leave out this arm? Maybe move the comment to be directly before this arm, which seems to be the main thing that's affected?
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 arm tells variable names (no upper case characters) and struct names (at least one upper case character) apart. I guess every test will fail without it. :)
As benchmark I used
I cannot say why the real time got so much better, if the user time got worse? All CPU cores only have around 33°C, so they should all be utilized in my test without thermal throttling. I guess I should try to find a better benchmark, but I guess without #834 we cannot properly benchmark the parser. :-/ I'll try to review your PR this weekend! |
(Feel free to just merge this after rebasing.) |
In the old implementation each variable in an expression would be parsed up to three times: * Try to parse a path because it contains a leading double colon, or infix double colons. * Try to parse it as path again by scanning for an identifier that contains an upper case character. * Fall back to scanning for any identifier. This PR turns all three steps into one, without the need for backtracking.
Not a huge difference, but it's a little better:
|
In the old implementation each variable in an expression would be parsed up to three times:
This PR turns all three steps into one, without the need for backtracking.