Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Tell c_read_binary that it's decoding characters
Browse files Browse the repository at this point in the history
These type and size hints let cython optimize the string decoding operation
to a pair of `__Pyx_PyObject_AsString` / `__Pyx_decode_c_string()` calls. This
is a lot more efficient than the previous code generation which invoked the
"encode" method on the abstract "py_data" object.

The performance improvement here varies based on how much string data exists
in the input buffer, but the benchmark suite shows a 40%+ speed improvement
with this change.
  • Loading branch information
jparise committed Jun 23, 2016
1 parent 5aa0b90 commit 724ebfa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion thriftpy/protocol/cybin/cybin.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ cdef inline c_read_binary(CyTransportBase buf, int32_t size):
cdef inline c_read_string(CyTransportBase buf, int32_t size):
py_data = c_read_binary(buf, size)
try:
return py_data.decode("utf-8")
return (<char *>py_data)[:size].decode("utf-8")
except:
return py_data

Expand Down

0 comments on commit 724ebfa

Please sign in to comment.