Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
b543eab8
Commit
b543eab8
authored
Aug 31, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow disabling method call optimisation with a directive
parent
1275882b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+2
-1
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-0
docs/src/reference/compilation.rst
docs/src/reference/compilation.rst
+14
-2
No files found.
Cython/Compiler/Optimize.py
View file @
b543eab8
...
...
@@ -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
)):
...
...
Cython/Compiler/Options.py
View file @
b543eab8
...
...
@@ -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
...
...
docs/src/reference/compilation.rst
View file @
b543eab8
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment