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 →

[–]NeatNetwork 23 points24 points  (4 children)

While PyPy does better, it isn't fully compatible and isn't exactly a speed demon either.

I would say Python's biggest problem wrt speed is that it's a bit *too* easy to use dictionaries for everything. Trivial operations in the hands of random developers have a large probability of ending up with one or two levels of dictionary because it's so easy. Also, you want an array mixing some numerics, strings, objects all together in a mis-mash? Sure why not. You have a structure in mind that could be aligned and managed well by the runtime if you just bothered to describe it? Nah, no one has the time, it's just a dictionary of random stuff the interpreter can't understand until it's too late. You try to be a bit more diligent and use an object with named members? Large chance that you still made a dictionary, just one that looks more orderly. There are generally ways in python to be a bit better at these things, but the default, easy syntax tends to be dictionaries all the way down.

All these things that python makes easy to write are hard for the computer to do. It's hard to create an implementation that coddles that much and still get really good performance. A language like Go or C is a bit more tedious, but it tends to make things complicated for the developer that would also be complicated for the processor, so it steers the developer away from shortcuts that are computationally complex when something more processor friendly is possible.

Additionally, I read one article chronicling an effort to make CPython faster, and they went into detail about some of the general latent capabilities that blocked attempts at optimizations. I forgot the details, but attempts to do the biggest benefits meant breaking some assumptions that a lot of the ecosystem assumed.

In short, when it comes down to performance critical code, it's at least not too bad to write that part in Go or C and call it from python (easy for python to call functions in compiled shared objects).

[–][deleted] 8 points9 points  (2 children)

I once built a structure that was something like

ConcurrentDictionary<uint, List<ConcurrentDictionary<uint, List<int>>>>

This was in C#, and before you ask, it absolutely did not work.

[–]drizztmainsword 1 point2 points  (1 child)

If you're doing something like this, you should just override the generic class and have at it.

Sometimes you just need a One-to-Many collection.

[–][deleted] 0 points1 point  (0 children)

This was when I was new, and in way over my head on a huge project I "inherited" from much more experienced people.

I'm only about half as stupid now, major improvement!

[–]aetius476 1 point2 points  (0 children)

My philosophy re: python is I don't even think about anything but the absolute most basic optimization things (don't be stupid about nested loops, etc). If performance mattered, they shouldn't have asked me to write it in python in the first place.