-
Notifications
You must be signed in to change notification settings - Fork 26
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
Strict parse Liquid::Variable.new objects to a Liquid::C::Expression #111
Conversation
.parse_context = parse_context, | ||
}; | ||
try_variable_strict_parse((VALUE)&parse_args); | ||
RB_GC_GUARD(markup); |
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'm not sure why this is needed. How is markup
at risk of being GC'd?
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.
isn't needed before try_variable_strict_parse
is called, so the markup
local variable could get re-used by the compiler and remove the reference to the object from the C stack. If the only reference to the markup
object were passed into this method, then in theory, it seems like the GC could end up cleanup the string before we are done using it.
It probably isn't needed in practice, but it makes the code more obviously correct.
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.
Thanks for clarifying!
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.
🤯
Just unsure about that push_nil at the end.
|
||
if (p.cur.type == TOKEN_EOS) | ||
if (p.cur.type == TOKEN_EOS) { | ||
vm_assembler_add_push_nil(code); |
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.
Not sure I understand why you need to push nil here? Is it to make an empty variable leave something on the stack? Since expressions must always return a value.
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.
Yeah, we need something left on the stack since it will be followed by a pop to get the return value
Strict parse Liquid::Variable.new objects to a Liquid::C::Expression (cherry picked from commit ea85e64)
This solves the problem that #96 intended to solve in a simpler way, so that PR can be focused on introducing support for compiling tags to VM code. Instead, this PR compiles the variable expression and filtering into a
Liquid::C::Expression
object that is stored in theLiquid::Variable
object's@name
instance variable, which will be evaluated on render.Benchmark
The liquid benchmark only uses the assign tag
{% assign article = pages.frontpage %}
and doesn't use the echo tag, so the benchmark is mostly for unaffected code. However, I wrote a micro-benchmark that shows the performance improvementresult on master
result on this branch