Practically every operation in Python starts with a hashtable lookup. Global and local environments are hashtables, modules are hashtables, objects are hashtables. Eventually you get down to C, which is usually very good---the hashtable implementation in particular---but for a lot of Python code the extra indirections are expensive. That's also why it is hard to optimize.
In this particular case, I don't think it's the problem, though. Just something to keep in mind.
In this particular case, I don't think it's the problem, though. Just something to keep in mind.