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): ...@@ -3764,7 +3764,8 @@ class FinalOptimizePhase(Visitor.CythonTransform, Visitor.NodeRefCleanupMixin):
function.type = function.entry.type function.type = function.entry.type
PyTypeObjectPtr = PyrexTypes.CPtrType(cython_scope.lookup('PyTypeObject').type) PyTypeObjectPtr = PyrexTypes.CPtrType(cython_scope.lookup('PyTypeObject').type)
node.args[1] = ExprNodes.CastNode(node.args[1], PyTypeObjectPtr) 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 # optimise simple Python methods calls
if isinstance(node.arg_tuple, ExprNodes.TupleNode) and not ( 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)): node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)):
......
...@@ -131,6 +131,7 @@ directive_defaults = { ...@@ -131,6 +131,7 @@ directive_defaults = {
# optimizations # optimizations
'optimize.inline_defnode_calls': True, 'optimize.inline_defnode_calls': True,
'optimize.unpack_method_calls': True, # increases code size when True
'optimize.use_switch': True, 'optimize.use_switch': True,
# remove unreachable code # remove unreachable code
......
...@@ -390,12 +390,24 @@ Cython code. Here is the list of currently supported directives: ...@@ -390,12 +390,24 @@ Cython code. Here is the list of currently supported directives:
``unraisable_tracebacks`` (True / False) ``unraisable_tracebacks`` (True / False)
Whether to print tracebacks when suppressing unraisable exceptions. 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 Whether to expand chained if-else statements (including statements like
``if x == 1 or x == 2:``) into C switch statements. This can have performance ``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 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 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 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