<p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>

<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</strong>:  When writing a program from scratch in python, what are some good ways to greatly improve performance?</p></li>
</ul>

<p>For the first question, imagine you are handed a decently written project and you need to improve performance, but you can't seem to get much of a gain through refactoring/optimization.  What would you do to speed it up in this case short of rewriting it in something like C?</p>

First thing that comes to mind:
psyco
. It runs only on x86, for the time being.
Then,
constant binding
. That is, make all global references (and
global.attr
,
global.attr.attr
…) be local names inside of functions and methods. This isn't always successful, but in general it works. It can be done by hand, but obviously is tedious.
You said apart from in-code optimization, so I won't delve into this, but keep your mind open for typical mistakes (
```
for i in range(10000000)
```
comes to mind) that people do.