diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2014-08-31 13:57:30 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2014-08-31 13:57:30 +0200 |
commit | b543eab8f9ef5355f265bf086fe51cce0c18eb1e (patch) | |
tree | adf8e997508fca77491656cf8eae199bdf795bd1 | |
parent | 1275882bd3a2cd900ccfffed14a9f8ee23c45724 (diff) | |
download | cython-b543eab8f9ef5355f265bf086fe51cce0c18eb1e.tar.gz |
allow disabling method call optimisation with a directive
-rw-r--r-- | Cython/Compiler/Optimize.py | 3 | ||||
-rw-r--r-- | Cython/Compiler/Options.py | 1 | ||||
-rw-r--r-- | docs/src/reference/compilation.rst | 16 |
3 files changed, 17 insertions, 3 deletions
diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 14f10d131..f2b007734 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -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)): diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index 013dff9f1..9dcf5d9b0 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -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 diff --git a/docs/src/reference/compilation.rst b/docs/src/reference/compilation.rst index 1e01089b7..caaa72488 100644 --- a/docs/src/reference/compilation.rst +++ b/docs/src/reference/compilation.rst @@ -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 |