I just listened to this presentation by Avery Pennarun about how Python can be very fast if you use the appropriate techniques, and how those techniques are actually graceful ones.

Here's a short summary of his points:

  • Use python modules that are implemented in C (e.g. regex)
  • threads in python are actually not good for CPU-bound calculations, since they really run in one thread underneath. but they're OK for I/O-bound operations such as reading from a hard drive.
  • If you do need to use threading for running multiple CPU-bound calculations simultaneously, you can do that in C.
  • python uses refcounting for garbage collection. this works very badly with threads. but it gives python a pretty good memory management profile overall.
  • python actually does have a garbage collector in the proper sense of it, but it is used to clear out orphaned objects with reference loops. Avoid that garbage collector at all costs. This means either breaking reference loops manually, or using "weakref" whenever possible.