-
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
Implement OP_WRITE_RAW on the instructions buffer #86
Conversation
The benchmark results don't seem right. I would expect parse time to be significantly slower due to having to copy the immediate argument for On master I got this for the benchmark
and on this branch (rebased) I got
which seems inline with what I expected. I was hoping to avoid slowing down rendering with this change. I think we could have a more efficient OP_WRITE_RAW instruction for a byte sized length argument to make rendering more comparable to what we have on master. |
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.
Code LGTM. I think introducing a wide version of the instructions might solve the performance regression.
ext/liquid_c/vm.c
Outdated
break; | ||
} | ||
case OP_WRITE_RAW_SKIP: |
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.
Doesn't look specific to write. Could it be renamed to OP_SKIP
?
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. Maybe even a more generic instruction like OP_JUMP
? I think a jump instruction will be useful in the future for many other purposes too. But a jump instruction should probably be signed (to be able to jump backwards). WDYT?
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.
Ah yeah jump! Good idea. Yes offset needs to be signed for for/while to work.
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.
Hmmm, if it's signed when we can only jump 8KiB relative if we use 24-bits, but OP_WRITE_RAW
could contain as much as 16KiB (unsigned 24-bits). Should we fall back to using 32-bits for the jump? Or maybe a different instruction for jumping forward vs. backwards?
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 don't think I've ever seen a specialized negative jump instruction. But that does sound a lot simpler. 👍
afae410
to
c95ba50
Compare
Have you tried using a shorter OP_WRITE_RAW instruction to fix the performance regression? How does that affect the benchmark results? |
@dylanahsmith I just changed This branch after the change:
This branch before the change:
Master:
|
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.
The implementation looks good. The performance impact also seems acceptable now. However, I think we now need unit tests to cover the OP_WRITE_RAW_W code paths, which will require raw strings in the template with a length of at least 256 bytes.
Rendering time seems almost unaffected w/ the wide instruction. I think we should be "ignoring" the parse speed when benchmarking since the goal is to cache the serialized template. Moving to wide instructions is effectively moving an operation from rendering to the parsing phase. So parse time is affected. But that will be gone when compiled templates are serialized. So we should be moving as much as possible to the parsing phase if it improves rendering time. |
e85d5eb
to
eae0382
Compare
933afdb
to
56e8d00
Compare
4b8f0e5
to
971611f
Compare
Implement OP_WRITE_RAW on the instructions buffer (cherry picked from commit ac408fe)
Implement OP_WRITE_RAW on the instructions buffer (cherry picked from commit ac408fe)
Implement
OP_WRITE_RAW
as an immediate instruction. The current implementation stores the size as a 24 byte unsigned integer after the instruction and thensize
number of bytes following it is the string. I also added aOP_WRITE_RAW_SKIP
instruction that skips skips the string. This instruction is used inBlockBody#remove_blank_strings
to replaceOP_WRITE_RAW
instruction. I'm not entirely satisfied in adding an extra instruction to handle this corner case. I've thought of two other ways to implement this:OP_WRITE_RAW_SKIP
instruction but will require an extra 8 bytes.c_buffer
that allows deleting sections from the middle. This is probably the cleanest solution but will have performance overhead ofmemmove
.Also see #77.
Benchmarks
Base branch:
This branch: