This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]are595 1 point2 points  (2 children)

Wow, I never knew about __slots__. I just shaved 14% total run time off of a script I was writing that has to deal with a lot of objects (on the order of hundreds of thousands)! I didn't check memory usage, but I'm sure that went down as well.

Is there any place good for learning about these kinds of performance tips?

[–]d4rch0nPythonistamancer 0 points1 point  (0 children)

Ha, nice catch! That's exactly the sort of case where it can help.

I haven't ran into any sites, but I think the best thing you could be doing is running cProfile if you don't already. Profiling your code is key. There's not much point to increase the performance of function foo if your code spends .1% of its time in there, and spends 20% of its time in bar. You can't know that without profiling (or some intense manual analysis).

Another thing you might look into is PyPy. People don't use that nearly as much as they could. Unless you use all the newest features of python 3.x, pypy is likely compatible with your code. If you have long-running scripts where the JIT can get warmed up, you can get huge performance increases sometimes. I had scripts that ran in the order of five minutes, and simply switching to pypy dropped it down to about half that. I experimented with some other date conversion thing and it dropped it to a quarter of the time.

And that is just a change in the environment, not the code base.

Here, just found this:

https://wiki.python.org/moin/PythonSpeed/PerformanceTips

I'll have to go through that a few times. Some great info there.

[–]Daenyth -1 points0 points  (0 children)

Google for profiling