Commit b543eab8 authored by Stefan Behnel's avatar Stefan Behnel

allow disabling method call optimisation with a directive

parent 1275882b
......@@ -3764,7 +3764,8 @@ class FinalOptimizePhase(Visitor.CythonTransform, Visitor.NodeRefCleanupMixin):
function.type = function.entry.type
PyTypeObjectPtr = PyrexTypes.CPtrType(cython_scope.lookup('PyTypeObject').type)
node.args[1] = ExprNodes.CastNode(node.args[1], PyTypeObjectPtr)
elif node.is_temp and function.type.is_pyobject:
elif (self.current_directives.get("optimize.unpack_method_calls")
and node.is_temp and function.type.is_pyobject):
# optimise simple Python methods calls
if isinstance(node.arg_tuple, ExprNodes.TupleNode) and not (
node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)):
......
......@@ -131,6 +131,7 @@ directive_defaults = {
# optimizations
'optimize.inline_defnode_calls': True,
'optimize.unpack_method_calls': True, # increases code size when True
'optimize.use_switch': True,
# remove unreachable code
......
......@@ -390,12 +390,24 @@ Cython code. Here is the list of currently supported directives:
``unraisable_tracebacks`` (True / False)
Whether to print tracebacks when suppressing unraisable exceptions.
``use_switch`` (True / False)
Configurable optimisations
--------------------------
``optimize.use_switch`` (True / False)
Whether to expand chained if-else statements (including statements like
``if x == 1 or x == 2:``) into C switch statements. This can have performance
benefits if there are lots of values but cause compiler errors if there are any
duplicate values (which may not be detectable at Cython compile time for all
C constants).
C constants). Default is True.
``optimize.unpack_method_calls`` (True / False)
Cython can generate code that optimistically checks for Python method objects
at call time and unpacks the underlying function to call it directly. This
can substantially speed up method calls, especially for bultins, but may also
have a slight negative performance impact in some cases where the guess goes
completely wrong.
Disabling this option can also reduce the code size. Default is True.
How to set directives
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment