Shopify / liquid-c

Liquid performance extension in C.
MIT License
120 stars 25 forks source link

Reduce copying in VM assembly by doing writes directly to the buffers #112

Closed dylanahsmith closed 4 years ago

dylanahsmith commented 4 years ago

While reviewing https://github.com/Shopify/liquid-c/pull/102, I noticed that the pattern of using c_buffer_write to write a struct results in double writing the value. We are writing the value to the struct local variable, then copying it to the buffer.

Instead, we could reserve space in the buffer and write directly to that buffer.

I've introduced a c_buffer_extend_for_write function that will help with that pattern by reserving space, incrementing the data_end pointer and returning a void pointer to write to the space just reserved for the write.