Differences between revisions 2 and 21 (spanning 19 versions)
Revision 2 as of 2006-10-01 00:03:42
Size: 1797
Editor: DavidHarvey
Comment:
Revision 21 as of 2022-04-05 05:32:13
Size: 0
Editor: mkoeppe
Comment: Outdated
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[ this page is under construction ]

= Introduction =

This page describes some techniques for writing really fast Pyrex code. It is aimed at SAGE developers who are working on low-level SAGE internals, where performance is absolutely crucial.

Pyrex is a very unusual language. If you write Pyrex as if it were Python, it can end up running as slowly as Python. If you write it like you're writing C, it can run almost as fast as pure C. The amazing thing about Pyrex is that the programmer gets to choose, pretty much line by line, where along the Python-C spectrum they want to work.

HOWEVER... it is ''hard work'' to make your Pyrex as fast as C. It's very easy to get it wrong, essentially ''because'' Pyrex makes it all look so easy. This purpose of this document is to collect together the experiences of SAGE developers who have learned the hard way.

=== How to contribute to this document ===

Yes, please do! Make sure to follow these guidelines:

 * When you give an example, make sure to constrast a ''fast'' way of doing things with a ''slow'' way, especially if the slow way is more obvious. Show both versions of the Pyrex code, and show the generated C code as well (if you think that this is useful to see).
 * Let's keep this scientific: show some evidence of performance (e.g. timing data).


= Examples =

== cdef functions vs def functions ==

[ todo ]

 * function call overhead -- constructing tuples
 * parseTuple stuff inside the def function

== python attributes vs cdef attributes ==

[ todo ]

== avoid python name lookups ==

[ todo ]

 * sage.rings.integer.Integer
 * PyObject_HasAttrString

== type checking ==

[ todo ]

 * PyObject_CheckType vs isinstance

== "==" vs "is" ==

[ todo ]

 * e.g. testing for None