Closed penguin-wwy closed 1 week ago
Hi @penguin-wwy , thanks for your effort. I see we replaced all specific types to generic pyobject. This may introduce overhead if we invoke from cython side. Are there some annotation to reduce checks for us automatically so we can avoiding change return types?
Hi @penguin-wwy , thanks for your effort. I see we replaced all specific types to generic pyobject. This may introduce overhead if we invoke from cython side. Are there some annotation to reduce checks for us automatically so we can avoiding change return types?
Yes, I found that this modification indeed disrupts cython's annotation optimization. However, I think we should write an appropriate Python microbenchmark, similar to what is done in integration_tests. This way, it will be easier to identify differences during optimization. I will draft this PR and proceed with the modifications once the microbenchmark is completed.
What does this PR do?
Optimize the C++ code generated by Cython by modifying the function implementations of the Buffer class.
Using
get_int8
as an example, the following C++ code is generated before modification.Since get_int32 returns a C++ type, the cython needs to generate calling
PyLong_FromLong
, and guard code such as callingPyErr_Occurred
. However, it is known that int32 can always be used to generate aPyLongObject
withPyLong_FromLong
. Therefore, when we manually call this, the cython only needs to check if the return value is null, as shown in the following code.Related issues
1887
Does this PR introduce any user-facing change?
Benchmark
Microbenchmark case:
Result: