-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Rewrite expression parser to a state machine in optional mixin #4768
Conversation
9cca465
to
864bf6e
Compare
Performance is now on-par with the old regex. |
It would be great to see if this PR could be done as an optional mixin. Hopefully there are enough hooks in the binding system to make this possible. The concern is the size and speed of the additional code here. This plus the fact that these issues are mostly pretty corner case makes me think that perhaps an optional mixin might be a better fit. |
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.
See: #4768 (comment)
Just a few eslint issues: https://travis-ci.org/Polymer/polymer/builds/265406074 |
3bece73
to
b03bca9
Compare
This is now extracted to a mixin and tested separately. We might still want to take a closer look at the performance. |
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.
Let's call this mixin something slightly more specific like perhaps StrictBindingParser
?
39f8664
to
7a51a10
Compare
@sorvell renamed! |
lib/utils/strict-binding-parser.html
Outdated
@@ -0,0 +1,405 @@ | |||
<!-- |
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.
Let's move this file to lib/mixins
since it's.... a mixin.
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.
Done
storeMethodVariable(bindingData, text, i); | ||
storeMethod(bindingData, templateInfo); | ||
bindingData.startChar = i + 1; | ||
storeMethod(bindingData, templateInfo); |
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.
Is this a typo to call storeMethod
a second time here? If so, let's fix and add a test to verify.
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.
@TimvdLippe acknowledged issue and will fix.
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 no longer have write access to this repository, so I submitted #4866 on this branch to fix the issue
We need to fix the test issues before merging. |
Hey @TimvdLippe, we talked about this a bit already, but there's a lot of overlap here with the polymer-expressions 2.0 branch: https://github.com/Polymer/polymer-expressions/tree/2.0-preview I think that recursive descent parsers are generally easier to reason about and maintain than hand-written state machines. It'd be interesting to see if polymer-expressions were suitable to use as the more strict parser either if 1) were stripped down to just the syntax and features that Polymer currently supports, or 2) we offered the full syntax as an opt-in for more powerful expressions. @kevinpschaaf mentions that this PR handles finding and matching the expression delimiters too, and that would need to be done for polymer-expressions. He and I have both not been able to put together the time to finish the push to integrating it is a mixin. I wonder if you could investigate that and try to get it actually working to compare against this option. |
@justinfagnani Yes I did consider using The pure state machine was the solution that did get very close (not 100% same speed), while it is more maintainable than the original regex (imo). I fear that a full-blown generalized parser (like in Nonetheless, I will try to port the expressions in a similar manner to this PR and confirm/deny my suspicion. |
198c937
to
211c223
Compare
@sorvell Build is passing now and docs + types are updated. |
For me: update the docs to state performance vs correctness trade-off, fix conflicts and then merge. Verbal LGTM by @sorvell |
Implement a new binding expression parser as statement machine instead of a regex. This solves the problem of maintaining a whitelist of characters that are allowed in bindings, e.g. it allows Japanese unicode characters, slashes, etc... It can better deal with unbalanced brackets, e.g.
{{asdf]]
and[[asdf}}
, since we can maintain state and escaping in strings is more intuitive.Regarding performance: I ran the supplied test on current master and on this branch. The new binding expression parsers took 950 ms for 1000 templates while current master took 700 ms. Have to take a deep dive in what is taking a lot of time, but would like to get some initial feedback first.
TODO:
Reference Issue
Fixes #1734
Fixes #1978
Fixes #3870
Fixes #4239
Fixes #4723
Supersedes and closes #3871