TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Yes, Python is Slow, and I Don’t Care

136 pointsby mithunmanohar1over 7 years ago

31 comments

scarface74over 7 years ago
I was all ready to savage his opinion after reading the headline but I agree looking at my architecture that I designed for the company I work for, CPU isn&#x27;t the bottleneck. Every time I try to increase performance by multi threading as much as possible, the databases start screaming.<p>On the other hand, the idea that dynamic languages are more productive than static languages are laughable. Statically type languages prevent a lot of bugs and allow for a lot of automated provably correct refactorings that simple cannot be done with a statically typed languages. You can&#x27;t even reliably do a &quot;find usages&quot; of classes using a dynamically typed language.
评论 #15200081 未加载
评论 #15200094 未加载
评论 #15199939 未加载
评论 #15200098 未加载
评论 #15199910 未加载
评论 #15200228 未加载
评论 #15199994 未加载
评论 #15201399 未加载
评论 #15200433 未加载
评论 #15200156 未加载
评论 #15199926 未加载
评论 #15202879 未加载
freetime2over 7 years ago
I pretty much agree with everything in the article - except for the bit where he tries to quantify why python is better from a developer efficiency perspective than other languages.<p>The main example he cites is a study that compares the amount of time writing string processing routines in different languages - which is quite a bit different from the work I do every day. I develop web apps which means I generally work in very large code bases, and spend most of my time modifying existing code rather than writing fresh code from scratch. I have found that statically typed languages (java + typescript) and the fantastic IDE support that comes along with them make it really easy to navigate around the code and refactor things. Also - the compiler tends to catch and prevent a whole class of bugs that you might otherwise only catch at runtime in a dynamically typed language.<p>Of course there are other situations where I prefer to use Ruby as my scripting language of choice - it all comes down to using the right tool for the job at hand. Unfortunately I don&#x27;t think the author gives enough consideration to the trade-offs between static vs. dynamically typed languages, and I think he would have been better just leaving that section out as it isn&#x27;t really necessary to prove his point that CPU efficiency isn&#x27;t important in a lot of applications.<p>Ultimately though I completely agree with his main point: &quot;Optimize for your most expensive resource. That’s YOU, not the computer.&quot;
mangecoeurover 7 years ago
Python is also heavily used in science, where performance really does matter. It&#x27;s successful because of how highly ergonomic python apis can be built on top of optimised C&#x2F;C++&#x2F;Fortran libraries.<p>That said, there is clearly a desire to write &#x27;fast&#x27; code in python itself without swapping to C. Cython helps, but to get really fast Cython code you actually have to write with C-semantics (so you are basically writing C with Python syntax).<p>Projects like numba JIT are interesting in that they can optimise domain-specific code (i.e. numerical&#x2F;array code) that&#x27;s written in normal python style. It also means jumping through a few hoops (although with the latest version in many cases all you need is a single decorator on your hot function). You can even do GIL-less multithreading in some cases.<p>Overall things are looking promising, with the addition of the frame evaluation API and possible improvements to the python C-api that could make JIT and similar extentions easier.
boomlindeover 7 years ago
The author argues from his professional experience as a Python developer that it&#x27;s fast enough, that you&#x27;ll spend most time waiting for I&#x2F;O anyway, that you can just throw more servers at the problem etc.<p>The problem is that his experience as a Python developer doesn&#x27;t accurately reflect the prevalence of problems where runtime CPU performance actually is an issue. Of course not, because who in their right mind would make an informed decision to solve such a problem in Python? Python has worked for him because it is only useless for a category of problems that he hasn&#x27;t had the opportunity to solve because he&#x27;s a Python developer. Outside this professional experience, not everything is a trivially parallel web service that you can just throw more servers at if CPU time exceeds I&#x2F;O waiting.<p>It all really boils down to what your requirements are, whether you have all the time and memory of a whole server park at your hands, or a fraction of the time available in a smaller embedded system, how timely the delivery of the software has to be and how timely it needs to deliver runtime results once it&#x27;s up and running. There are times where Python just isn&#x27;t fast enough, or where getting it fast enough is possible, but more convoluted and tricky than implementing the solution in a more performant language. Developer time may be more expensive than the platform that my solution is for, but that doesn&#x27;t get around the fact that it eventually will need to run with the available resources.
agentgtover 7 years ago
Unless we are talking like circa 1999 I don&#x27;t think I have heard a complaint yet that Python is slow. I&#x27;m curious who or where the author heard that from (not specifically the people themselves but the domain they are in).<p>What I have heard complaints about Python are (and I don&#x27;t agree with all these points):<p>* Its not statically typed<p>* The python 2&#x2F;3 compatibility<p>* It has some design flaws: GIL, variable assigning, mutable variables, lambdas, indentation (I don&#x27;t agree with all these but this is complaints I have heard).<p>* The plethora of packaging (ie its not unified)<p>I guess one could argue its slow because it can&#x27;t do concurrency well but that really isn&#x27;t raw speed.<p>Then the author started comparing string processing of programmer time from a study which... doesn&#x27;t help the authors point at all.<p>* Python has and will always be fast at string processing and most people know this<p>* The people that complain about python speed are almost certainly not doing string processing<p>* I have serious questions about the study in general (many languages have changed quite a bit since then)
评论 #15200065 未加载
评论 #15200066 未加载
评论 #15200307 未加载
评论 #15200636 未加载
评论 #15199970 未加载
评论 #15200209 未加载
评论 #15199948 未加载
评论 #15200122 未加载
评论 #15200210 未加载
icebrainingover 7 years ago
&quot;It doesn&#x27;t matter than Python is slow, besides we can use compiled libraries to speed it up&quot;<p>&quot;People saying it doesn&#x27;t matter that Python is slow are deluding themselves and preventing Python from getting faster like JS did&quot;<p>&quot;Python is inherently harder to optimize than JS since it has &lt;very dynamic features&gt;&quot;<p>&quot;Smalltalk&#x2F;Lisp&#x2F;etc are also very dynamic yet are much faster&quot;<p>&quot;The slowness of Python is harming the planet by being inefficient and therefore wasting more energy&#x2F;producing more pollution&quot;<p>Did I miss any arguments? I know certain topics are bound to attract some repetitive discussion, but &quot;Python is slow&quot; has been one of the worst.
评论 #15199808 未加载
评论 #15200579 未加载
评论 #15199881 未加载
Waterluvianover 7 years ago
Python is my Swiss army knife. I love it because it is a single tool that can aid in almost every project I do. But if I&#x27;m doing one specific thing a lot, I want that thing to be done well and done efficiently, so I&#x27;ll reach for the specific screwdriver I need.<p>Also most of my problems are IO bound so single threaded concurrency is fine.<p>But I represent a very small portion of the global problem space.
dom96over 7 years ago
The fact that Python is slow isn&#x27;t its only problem. What I care more about nowadays is wasting my time hunting bugs that could have been avoided by a static type system.
评论 #15199967 未加载
评论 #15199945 未加载
评论 #15199951 未加载
评论 #15199920 未加载
评论 #15199843 未加载
dahartover 7 years ago
Python&#x27;s value to me has always been that it&#x27;s easier to get things done, not it&#x27;s speed. One time when I was interviewing a candidate for a coding job, the candidate said she loved Python the most &quot;because you can just yell at it and it&#x27;ll work.&quot;<p>It&#x27;s both the breadth of the standard library and ecosystem, and the simple language design, that make developing things in Python faster for me.<p>Doing problems on Project Euler has been an education for me in how algorithm matters more than speed. Lots and lots of people spend hours writing long C++ codes that are easily beaten by a few lines of Python. It certainly goes the other way too, and the wrong algorithm in Python is even that much slower and more painful than the right algorithm in C++. But when the right algorithm is used and the problem is solved in a few milliseconds, it really doesn&#x27;t matter which language uses more CPU cycles, all that matters is whether you saw the insight that let you skip 99% of the search space, and how much time you spend writing code.
_pmf_over 7 years ago
Somewhat ironically, Python is used a lot for things that would benefit from raw speed (data processing pipelines) and do not benefit at all from dynamic typing (since the kind of property bags &#x2F; data frame views over data are easily replicated in statically typed languages). But Python&#x27;s C extension API is quite a bit easier than p.e. Matlab&#x27;s MEX API (to me at least); can typical Python IDEs compile and relink extension modules without an external build step?<p>&gt; Your bottleneck is most likely not CPU or Python itself.<p>With applications that are dominated by raw data processing, it&#x27;s very, very easy to be CPU dominated. Hell, I had one quite trivial data converter for logfiles where the &quot;parsing the printf string&quot; part of Java&#x27;s printf dominated processing and writing a custom formatter halved processing time (while regexes can be compiled, the format string cannot be precompiled and will be interpreted each time); it&#x27;s one of those things where I would intuitively say &quot;why did this moron write his custom formatter&quot; if I stumbled upon it in a code review. Intuitively, you&#x27;d expect this to be a simple case of an IO dominated task (which it is now once the bottleneck has been removed).<p>If it&#x27;s fire-and-forget batch jobs, you can get away with it, but if the converter is part of a user facing fat client application that runs on a old office laptop, you don&#x27;t have that luxury.
kodablahover 7 years ago
The article could be titled: &quot;Yes, Python is Slow To Refactor and Maintain, and I Still Don&#x27;t Care&quot;.<p>I never understand why dynamic language enthusiasts primarily focus on new code only. You have to discuss all sides of increased or decreased productivity to make a rational argument.
评论 #15205706 未加载
wyldfireover 7 years ago
&gt; Your bottleneck is most likely not CPU or Python itself.<p>I&#x27;ve found that this is often the case. Nearly always disk or network. But it&#x27;s sometimes surprising how little work you need to do to become CPU-bound. This is the price we pay for such a tremendously dynamic language.<p>Indeed, the article&#x27;s suggestions of C&#x2F;Cython&#x2F;PyPy are good ones to remedy the problem when it occurs.
jayfluxover 7 years ago
I get the point this guy is making, but if you need something parallel for a cpu bound task, throwing more hardware at the problem isn&#x27;t the most efficient solution if you can just use more cores. For example adding another quad core when the first cpu is only using one core anyway is inefficient and expensive.<p>Right tool for the right job I suppose.
评论 #15200230 未加载
评论 #15201748 未加载
nadamover 7 years ago
&quot;It used to be the case that programs took a really long time to run. CPU’s were expensive, memory was expensive. Running time of a program used to be an important metric.&quot;<p>As hardware gets faster we give it new tasks that could not be achieved before. Like rendering high resolution stereoscopic images using physically based shading at 90 FPS on relatively cheap consumer hadware (VR). There are still quite a lot of code that we call &#x27;performance critical&#x27;. Most of that code is written in C&#x2F;C++ (and CUDA and glsl, and hlsl, etc...) today.
评论 #15200175 未加载
评论 #15200885 未加载
VHRangerover 7 years ago
The problem is not so much that python is slow. It&#x27;s that in some scenarios python can&#x27;t be made fast.<p>Fast prototyping is great but being stuck with a prototype for deployment isn&#x27;t.
评论 #15199766 未加载
评论 #15199761 未加载
评论 #15199707 未加载
评论 #15199793 未加载
评论 #15199715 未加载
traversedaover 7 years ago
There&#x27;s are still some big gains python could make, if python implementations were better.<p>Micropython is equivalent to a real-time cooperative-multitasking OS. If it had ~~better~~ support for things like cffi, you could implement posix on top of it. I can imagine a laptop that runs gnu+python in the next few years.<p>That&#x27;s a whole new usecase, simply because that implementation uses a lot less ram. What usecases would we discover for a faster python?<p>Shared objects and proper sandboxing would also be huge.
评论 #15200079 未加载
booshiover 7 years ago
This keeps getting posted, and while it makes some valid points, it&#x27;s a lot of handwaving.<p>Arguably, other languages can get code out faster depending on the dev, language, etc.
评论 #15200224 未加载
评论 #15199866 未加载
bluedinoover 7 years ago
Many times when Python is blamed for being slow, it&#x27;s the programmers fault. Python is great that you can &#x27;regular&#x27; people writing code in it quickly. The problem is, these regular people don&#x27;t always understand algorithms or things like caches, threads, databases...<p>A lot of these users can just say &quot;My department needs a $40,000 24 CPU server with maximum RAM from MicroWay&#x2F;SuperMicro, we need to run our codes faster&quot;, when they are just trying to brute force things.<p>They understand the problem domain but don&#x27;t have the programming skills to use a computer to efficiently solve it.<p>But, these guys are all a step ahead of the ones who are stuck in the mindset of &quot;C is the only language fast enough for my work&quot;, while not even understanding pointers and basic syntax and getting stuck on silly things like text processing, which could be done in minutes in Python.
nhumrichover 7 years ago
Author here. Surprised to see this toping HN. Appreciate all the feedback. Let me know if you have any questions.
progmanover 7 years ago
Yes, time to market is important. However, you don&#x27;t need to compromise convenience of development for the sake of performance. If you twist your Python code to get performance it takes time. If you need performance, and like the syntax of Python then you should take a look at Nim [1]. With Nim I develop as quickly as in Python while I get the performance of C.<p>[1] <a href="https:&#x2F;&#x2F;nim-lang.org" rel="nofollow">https:&#x2F;&#x2F;nim-lang.org</a><p>I believe application performance <i>is</i> important on servers. It makes a difference if your Shop software written in Python is able to handle 50 requests per second, or if the same software written in Nim can handle 500 rps. And by the way, Nim provides static typing which helps a lot to catch errors at compile time.
评论 #15201010 未加载
deadsyover 7 years ago
Premise: It&#x27;s more important to be productive than to have fast code. Conclusion: Use Python. Is the premise true? For many cases- yes, but it depends. If you are running an application on the cloud and your metric is $&#x2F;user&#x2F;year and you have many users then saving some compute resources for each user gets attractive and you don&#x27;t want to just throw another VM at it.<p>Is the conclusion true? Garbage collection gives big productivity gains. Other languages have GC. It&#x27;s not nice to see your Python code die after a few days because you messed up the type passed to a function. Other languages fix that at compile time. Multicore is now. Other languages are built with better multicore awareness.
__sover 7 years ago
&gt; without getting stuck in the weeds of the small things such as whether you should use a vector or an array<p>Yes, instead get into the weeds of tuple vs list<p>Not included in the graph of time-to-solve-problem static languages: statically typed languages with type inference
评论 #15200560 未加载
agnivadeover 7 years ago
&gt; However, this is no longer true, as silicon is now cheap. Like really cheap. Run time is no longer your most expensive resource.<p>Our client won&#x27;t spend more money than a t2.medium instance on aws. Nothing we can do about it. In that case, run time does become an expensive resource.<p>But I get the point that OP is trying to make. Just wanted to mention that not all of us have the comfort of having enough resources on which our app runs.
fiatjafover 7 years ago
&gt; It’s more important to get stuff done than to make it go fast.<p>This is not a real absolute. It is only valid when what you have to run will not benefit a lot from performance or suffer a lot from lack of it.<p>The real guidance you can have in these matters is: how many times is my code going to run per second?<p>Some programs are written to be run once a day, others 10000000 times in a second. The first ones should be written in the language you&#x27;re most productive in, the second ones in the fastest possible language.
karmakazeover 7 years ago
Putting aside the discussion regarding productivity, there is a case where I have found execution time to matter. Scaling an application which uses an unsharded database. The long transaction durations and number of connctions were bottlenecking db throughput. The particular app was a Ruby&#x2F;Rails monolith.
nervous123over 7 years ago
This sentiment is the reason for almost all software (especially on the web) beeing a load of crap. It&#x27;s slow, it&#x27;s buggy and developers always give the same excuse: CPUs and memory are cheap, therefore we can waste our customers time.<p>Imagine what we could do with the amazing hardware we have, if people started to do the sane thing and actually use the hardware to do things efficiently.
Thaxllover 7 years ago
Giving EvE Online as an example is bad because that game artificially slow the game loop to keep up with the number of players, would this happen with C++ on a recent architecture? Probably not.
sedlichover 7 years ago
In &quot;What if CPU time is an issue?&quot; we could also mention the nim language (and not only cython) because it compiles (not only) to C and feels like python.
donatjover 7 years ago
I know it&#x27;s not trendy, but I would argue PHP is as productive for developers as Python and has a MUCH faster runtime, particularly after 7.
snarfyover 7 years ago
Slow doesn&#x27;t matter when you scale horizontally.
hellofunkover 7 years ago
Yeah? Well, Jimmy Crack Corn and <i>I</i> don&#x27;t care.