Python is Slow, and I Don't Care
medium.com
medium.com
As a Googler, I could relate countless stories of systems that were cobbled together in Python and then scaled up with massive investment, then later rewritten in C++ or Go, and generally ran with 100x fewer resources. Hell, from what I can tell, almost all of YouTube was written in Python and has or is still being rewritten in C++, Java, and Go, saving XX millions of dollars per year of CPU time.
Sure, prototype with Python. But by the time you get to scaling out a huge service, it's probably time that you rearchitected the system anyway, and you should spend the engineering effort to make it efficient.
Also, you are saying that google hit a scale where it really WAS expensive to use python. Twitter had a similar issue with Ruby. That makes sense for a huge company like google, twitter, etc. But for most of us, our companies/projects will never get the scale that youtube has.
This kind of story comes again all the time, but the most important detail is always missing: how much of that 100x can be attributed to the language, and how much can be attributed to now I know the domain better, I know where the pitfalls are, how to model the problem, and when I need to optimize ? Because arguably the second one can bring a lot.
Domain knowledge for me is higher in C#, both were optimized as far as I could figure out.
There are dozens of cpu instructions you can't even make happen in most runtime GC languages. It is banananastown.
If you reach YouTube scale, maybe the CPU savings > developer time.
But I don't think you will reach that scale if you start with C++. Completion will outpace you in no time.
and now you have to context switch in your head more often, and the build process is more complex, and usually there is a cost when you do the FFI.
If you are starting a new startup, with Python or Ruby or PHP you may be able to try 2-3x ideas in the same time. Which means 2-3x more chances of succeeding.
If you are adding a new service to an existing businesses, it may worth the time investing in some middle-ground.
If you are google or facebook, I guess rewriting everything makes sense from financial point of view.
Often "We moved from X to Y because X is slow" is seen as a failure of X, but it is not. It could mean the feature was deployed quickly, caught on and has customers which want to use it. So it can be a testament of how productive X is.
With large systems you want assurances at compile time, something that Python can't give you much of. When you have a huge system with many modules that interact in ways you can't expect anyone to map out without staring at a lot of code, it pays to have a stronger type system and fewer runtime errors.
For experimentation and small-scale work, Python's great. Single client application? Fantastic (e.g Dropbox). Giant web service or distributed application? Starts to show its ugly sides quickly.
I think both are valid approaches depending on your application, available resources, nature of incentives, and the speed at which your market moves.
There are plenty of future YouTubes who don't want to be acquired and instead are looking to be long term companies. They'd do well to avoid the pain and cost. There are ways to achieve velocity and maintainability, they're not mutually exclusive.
I'm in a very python heavy company, and maintains the python architecture that are being used on hundreds of servers. The ugly part(lack of restriction, multiprocessing, distribution) quickly shows why it's not suited for very large system.
But I'm curious at which point, we would be so annoyed as to decide to rewrite the whole stuff.
There's just too many things to take into account:
- the developer's experience with a particular language
- the developer's experience with the problem domain / understanding of the task / etc.
- time spent writing the code but also time spent debugging it
- time spent debugging a few weeks later when it suddenly breaks in production (dynamic typing often fails there)
Really, the most productive language is the one you're most familiar with.
I still use Python and Ruby for various tasks (mostly for scripting, command-line apps, simple services). Their main advantages are their library ecosystems and portability* . But they aren't very good for serious app development. Even when you feel like your business logic is extremely simple, you WILL get that weird null (sorry, None) or completely unexpected exception in production.
* I mean, you can easily run a Python script on, say, an iBook G4 running OpenBSD/macppc, or an old ReadyNAS with Debian/SPARC, or your MIPS home router. I like obscure hardware :)
> If Python is your bottleneck (you’ve already optimized algorithms/etc.), then move the hot-spot to Cython/C
After "If Python is your bottleneck", I'd just add "then try PyPy because there's a decent chance everything will Just Work and Be Faster." Sometimes you run into portability bugs in your code, other people's code, and sometimes you run into compatibility problems. But most of the time it Just Works.
Now take this sentence and apply it to the end user of your software.
From your viewpoint: You've got a large constant X (representing time taken doing something un-optimizable like I/O), a small constant Y (representing the "language multiplier"), and a small constant Z (representing CPU-heavy work). So you've got something like Time=N(X+Y*Z), which for values of Y and Z in your work, means that X is by far the largest timesink.
From my viewpoint: You're talking past each other, imagining different constants. It's also interesting to me that a program is still considered written in "Python" if the interesting parts are actually in C, and called from Python. You make points that I agree with about premature optimization, but I think the way you wrote your article opens it to easy misinterpretation, since everyone will view it through their workloads (which may vary strongly from yours). I would've limited the discussion explicitly to the kinds of use-cases you're thinking of.
I've seen this applied to the Linux kernel, where saving a few microseconds in a system call, when multiplied out to the billions of machines running Linux, saves hundreds of years of CPU time.
With that said, most services don't have as many users as Linux.
Does the fast version save you more time than it cost by not being available?
If the software is better than anything else available, then the user is optimizing their time within their own constraints. If the users complain that it's too slow and you lose users as a result, then go ahead and optimize. But slow and working is better than fast and imaginary.
As a software user, is completely agree with you! I get frustrated by badly performing software so often I regularly wonder if I'd be happier doing something that relied less on shitty software.
More interesting than the actual content is the question why this topic is of such perennial interest, is it a feeling of inferiority of programmers working in higher-level but slower languages? Or frustration with coworkers wasting time on premature optimization? Probably a mixture of both.
Python 3 cared pretty much everything else except for speed and now 10 years had passed it didn't go anywhere.
Even if Python 3 was 10x as fast, sysadmins would hesitate to put what's effectively an unsupported version of Python on their systems.
Massive performance increases would help to sway those who have the freedom to move to a different Python without being locked to their system, I agree about that much.
Python 3.6 is basically at speed parity with Python 2. There are a few outliers, but in most cases 3 is as fast or faster than 2.
Python 3 adoption is exactly where the devs wanted it to be 10 years later. Almost all major libraries have been ported. Python 3 adoption is only growing. More than 30% of new projects use it. Expect that to grow substantially as 3.6 is adopted.
"didn't go anywhere" is therefore FUD.
(I know -- the libraries aren't as good.)
pretty simple concept. surprised that people don't understand that.
(mind you, python is about as performant as I like for the tasks I use it for, so ymmv with the above.)
I think you are referring to the fact that devs LIKE speed. And they want things to be fast. I mean, your right. We like speed. Probably a lot more than we should. But those who only care about speed simply wont have as successful careers as those who care about productivity (10xers?), unless your lucky enough to be put on a project that is designed entirely for speed. Lots and lots of tools exist that are "slow", but we use them over faster alternative's because of the features they provide. One simple example is IDE's. I think its pretty narrow-viewed to say all projects will fade because they aren't "as fast as they can be". Everything only needs to be fast enough.
What they fail to realize is that JS, for instance, can reach about 50% of the speed of C code nowadays. If Python could be that fast, you could use it to write videogames and all other kinds of software that you can't realistically write in Python today. It could displace a lot of C++ code. The poor performance of Python is actually limiting its adoption.
Python has poor performance, and a very poor handling of multithreading, at a time when single-core performance is stagnating. I think it's inevitable that people will start migrating away from it eventually. I mean, if you could have something like Python, but 20x better performance, would you take it?
There was some assembly and C at the very core, but every point generated was a Python tulle at one point in processing.
Allow me to point out some important points of disagreement here.
“Speed no longer matters”
While computers are faster, the expectations of users are also higher. New monitors today have 14,745,600 pixels and that is still growing fast, that is 7 times more than 1920x1080 which was the norm just a couple of years ago. That means for any app involving UI or graphics, you have significantly more work to do. This same trend applies to processing data, as databases are also bigger, complexity and amount of features expected has also increased. To keep up with that you can’t throw away cycles.
While computers are faster, many more people are doing computing on small devices like phones and tablets where battery power is a precious resource, and slow code wastes battery life faster.
The cost of scaling server side infrastructure can seem cheap with a naive analysis, but high performance code can not only mean fewer servers or cloud services to buy, but also a simpler architecture. As soon as you have to scale beyond 1 web server for instance, you now also need to worry about load balancing, and a host of other issues. High performing code can keep you on a single server for an amazingly huge workload.
Lower latency has been proven to make money https://blog.gigaspaces.com/amazon-found-every-100ms-of-late...
Another point of disagreement is the idea that this performance his we take with interpreted Python is completely unnecessary. Exactly the same language can exist in JITted form, and does, and it should be brought up to be the default and only way of executing python. There also exist plenty of similarly nice and expressive languages that perform better (OCaml, F#, etc)
Every day I am annoyed by slow software, and until that stops I will never accept the argument that performance doesn’t matter.
Yes, PyPy, Jypthon, etc. exist and they can be faster. If you want to use those, then great, do it! But a JIT is not faster in all cases, only some cases. Python is first and foremost a scripting languages, and for a lot of the simple script cases, CPython is faster than a JIT version. It doesnt make sense to make that the default.
If the argument is that for really short programs the iteration time when building and running is faster with the interpreter, because you don't have to build, I can't see how this matters. It would be a sub microsecond difference for short scripts. If it isn't, make a better JIT. (or even better, native compile it, as all things should be in my fever dreams)