1/1/2026 at 7:11:14 PM
A lot of people here are commenting that if you have to care about specific latency numbers in Python you should just use another language.I disagree. A lot of important and large codebases were grown and maintained in Python (Instagram, Dropbox, OpenAI) and it's damn useful to know how to reason your way out of a Python performance problem when you inevitably hit one without dropping out into another language, which is going to be far more complex.
Python is a very useful tool, and knowing these numbers just makes you better at using the tool. The author is a Python Software Foundation Fellow. They're great at using the tool.
In the common case, a performance problem in Python is not the result of hitting the limit of the language but the result of sloppy un-performant code, for example unnecessarily calling a function O(10_000) times in a hot loop.
I wrote up a more focused "Python latency numbers you should know" as a quiz here https://thundergolfer.com/computers-are-fast
by thundergolfer
1/2/2026 at 8:51:27 AM
I do performance optimization for a system written in Python. Most of these numbers are useless to me, because they’re completely irrelevant until they become a problem, then I measure them myself. If you are writing your code trying to save on method calls, you’re not getting any benefit from using the language and probably should pick something else.by saagarjha
1/2/2026 at 11:49:31 AM
It's always a balance.Good designs do not happen in a vacuum but informed with knowledge of at least the outlines of the environment.
One can have a breakfast pursuing an idea -- let me spill some sticky milk on the dining table, who cares, I will clean up if it becomes a problem later.
Another is, it's not much of an overbearing constraint not to make a mess with spilt milk in the first place, maybe it will not be a big bother later, but it's not hurting me much now, to be not be sloppy, so let me be a little hygienic.
There's a balance between making a mess and cleaning up and not making a mess in the first place. The other extreme is to be so defensive about the possibility of creating a mess that it paralyses progress.
The sweet spot is somewhere between the extremes and having the ball-park numbers in the back of one's mind helps with that. It informs about the environment.
by srean
1/1/2026 at 11:21:54 PM
No.Python’s issue is that it is incredibly slow in use cases that surprise average developers. It is incredibly slow at very basic stuff, like calling a function or accessing a dictionary.
If Python didn’t have such an enormous number of popular C and C++ based libraries it would not be here. It was saved by Numpy etc etc.
by Scubabear68
1/2/2026 at 11:11:46 AM
I'm not sure how Python can be described as "saved" by numpy et al., when the numerical Python ecosystem was there near the beginning, and the language and ecosystem have co-evolved? Why didn't Perl (with PDL), R or Ruby (or even php) succeed in the same way?by aragilar
1/2/2026 at 12:12:38 PM
22ns for a function call and dictionary key lookup, that's actually surprisingly fast.by HenriTEL
1/2/2026 at 6:55:33 PM
In that time the java app parsed 50 strings for object hierarchies (using a regex that isn't cached) and extracted values from a request object to a processing object, handled errors, and logged results.3 times.
This is the naive version of that code, because "I will parallelize it later" and I was just getting the logic down.
Turns out, when you use programming languages that are fit for purpose, you don't have to obsess over every function call, because computers are fast.
I think people vastly underestimate how slow python is.
We are rebuilding an internal service in Java, going from python, and our half assed first attempts are over ten times faster, no engineering required, exactly because python takes forever just to call a function. The python version was dead, and would never get any faster without radical rebuilds and massive changes anyway.
It takes python 19ns to add two integers. Your CPU does it in about 0.3 ns..... in 2004.
That those ints take 28 bytes each to hold in memory is probably why the new Java version of the service takes 1/10th the memory as well.
by mrguyorama
1/3/2026 at 8:08:13 PM
22ns might be about 100 processor instructions. Somehow I doubt that any programming language can parse 50 strings in 100 instructions, let alone with naive code.by igiveup
1/5/2026 at 4:22:36 PM
You are right.I have said something very wrong. Java may be fast but it isn't magic.
What I claimed is not possible and I should have realized that.
I can not correct my previous claim. I wish HN had longer edit windows and I wish HN allowed you to downvote older comments.
I cannot erase this wrong info
by mrguyorama
1/3/2026 at 10:54:52 AM
Python is slow but in my experience (that mostly relates to web services and data processing) I found that I/O was by far the biggest bottleneck. Waiting for the database, another http service or local storage, which often takes more than 1ms anyway.by HenriTEL
1/3/2026 at 4:19:40 PM
Yep.Except when it’s not I/O.
by Scubabear68
1/2/2026 at 4:02:54 AM
i hate python but if your bottleneck is that sqlite query, optimizing a handful of addition operations is a wash. thats why you need to at least have a feel for these tablesby dnautics
1/2/2026 at 12:47:33 AM
Agreed, and on top of that:I think these kind of numbers are everywhere and not just specific to Python.
In zig, I sometimes take a brief look to the amount of cpu cycles of various operations to avoid the amount of cache misses. While I need to aware of the alignment and the size of the data type to debloat a data structure. If their logic applies, too bad, I should quit programming since all languages have their own latency on certain operations we should aware of.
There are reasons to not use Python, but that particular reason is not the one.
by NoteyComplexity
1/1/2026 at 7:21:52 PM
I think both points are fair. Python is slow - you should avoid it if speed is critical, but sometimes you can’t easily avoid it.I think the list itself is super long winded and not very informative. A lot of operations take about the same amount of time. Does it matter that adding two ints is very slightly slower than adding two floats? (If you even believe this is true, which I don’t.) No. A better summary would say “all of these things take about the same amount of time: simple math, function calls, etc. these things are much slower: IO.” And in that form the summary is pretty obvious.
by oofbey
1/1/2026 at 7:45:18 PM
I think the list itself is super long winded and not very informative.I agree. I have to complement the author for the effort put in. However it misses the point of the original Latency numbers every programmer should know, which is to build an intuition for making good ballpark estimations of the latency of operations and that e.g. A is two orders of magnitude more expensive than B.
by microtonal
1/1/2026 at 8:17:50 PM
our build system is written in python, and i’d like it not to suck but still stay in python, so these numbers very much matter.by i_am_a_peasant
1/2/2026 at 6:10:22 AM
For some of these, there are alternative modules you can use, so it is important to know this. But if it really matters, I would think you'd know this already?For me, it will help with selecting what language is best for a task. I think it won't change my view that python is an excellent language to prototype in though.
by notepad0x90
1/2/2026 at 11:34:54 AM
> ... a function O(10_000) times in a hot loopO(10_000) is a really weird notation.
by TacticalCoder
1/2/2026 at 12:06:38 PM
Generously we could say they probably mean ~10_000 rather than O(10_000)by tialaramex
1/3/2026 at 3:24:24 PM
I meant it as an order-of-magnitude notation, so means more like 10,000-90,000. Eg. calling the function 3,000 times is OK, but 30,000 is too much. Odd notation, yes, but I've picked it up somewhere along the way.by thundergolfer
1/4/2026 at 6:38:54 PM
I think it follows naturally from speech. People say "order ten thousand" pretty naturally. Big-O notation is often vocalized as "order". But technically it's a a clash of ideas when written that way.by oofbey
1/1/2026 at 7:21:38 PM
> A lot of important and large codebases were grown and maintained in PythonHow does this happen? Is it just inertia that cause people to write large systems in a essentially type free, interpreted scripting language?
by nutjob2
1/1/2026 at 8:05:58 PM
Small startups end up writing code in whatever gets things working faster, because having too large a codebase with too much load is a champagne problem.If I told you that we were going to be running a very large payments system, with customers from startups to Amazon, you'd not write it in ruby and put the data in MongoDB, and then using its oplog as a queue... but that's what Stripe looked like. They even hired a compiler team to add type checking to the language, as that made far more sense than porting a giant monorepo to something else.
by hibikir
1/1/2026 at 7:27:36 PM
It's very simple. Large systems start as small systems.by xboxnolifes
1/1/2026 at 9:24:37 PM
Large systems are often aggregates of small systems, too.by dragonwriter
1/1/2026 at 7:30:35 PM
It’s a nice and productive language. Why is that incomprehensible?by oivey
1/1/2026 at 7:23:12 PM
It’s very natural. Python is fantastic for going from 0 to 1 because it’s easy and forgiving. So lots of projects start with it. Especially anything ML focused. And it’s much harder to change tools once a project is underway.by oofbey
1/1/2026 at 7:57:30 PM
this is absolutely true, but there's an additional nuance: yes, python is fantastic, yes, it's easy and forgiving, but there are other languages like that too. ...except there really aren't. other than ruby and maybe go, every other popular language sacrifices ease of use for things that simply do not matter for the overwhelming majority of programs. much of python's popularity doesn't come from being easy and forgiving, it's that everything else isn't. for normal programming why would we subject ourselves to anything but python unless we had no choice?while I'm on the soapbox I'll give java a special mention: a couple years ago I'd have said java was easy even though it's tedious and annoying, but I've become reacquainted with it for a high school program (python wouldn't work for what they're doing and the school's comp sci class already uses java.)
this year we're switching to c++.
by passivegains
1/1/2026 at 10:48:59 PM
Omg, switching to C++ for pupils programming beginners ... "How to turn off the most students from computer programming?" 101. Really can't get much worse than C++ for beginners.by zelphirkalt
1/2/2026 at 2:31:17 AM
PSU (Oregon) uses C++ as just "c with classes" and ignores the rest of C++ for intro to programming courses. It frustrates people who already use C++ but otherwise works pretty well.by nightfly
1/2/2026 at 2:35:42 PM
We should distinguish "First language" classes (for Computer Scientists who will likely learn many other languages and are expected to graduate knowing enough to just pick up another language with self study in reasonable time) from "Only language" classes for subjects where you might find it useful to write some software. These have different goals, it wouldn't make sense to teach say, OCaml as the only language but it's entirely reasonable as a first language.by tialaramex
1/2/2026 at 12:16:50 PM
This was how we learned it in an intro class in highschool ages ago, worked pretty well there too.by Izkata
1/2/2026 at 12:36:50 PM
C++, The Good Partsby jgalt212
1/2/2026 at 6:41:49 PM
Back in the 1990's, C++ used to be taught at high school students and first year university students.by pjmlp
1/3/2026 at 2:03:41 AM
I just went and checked my university - they’re still teaching c++ to first year uni students in 2025by maccard
1/2/2026 at 6:40:53 PM
Cough, Lisp.by pjmlp
1/1/2026 at 10:37:19 PM
Python has types, now even gradual static typing if you want to go further. It's irrelevant whether language is interpreted scripting if it solves your problem.by wiseowise
1/1/2026 at 10:29:37 PM
Most large things begin life as small things.by tjwebbnorfolk
1/1/2026 at 11:43:25 PM
Someone says "let's write a prototype in Python" and someone else says "are you sure we shouldn't use a a better language that is just as productive but isn't going to lock us into abysmal performance down the line?" but everyone else says "nah we don't need to worry about performance yet, and anyway it's just a prototype - we'll write a proper version when we need to"...10 years later "ok it's too slow; our options are a) spend $10m more on servers, b) spend $5m writing a faster Python runtime before giving up later because nobody uses it, c) spend 2 years rewriting it and probably failing, during which time we can make no new features. a) it is then."
by IshKebab
1/2/2026 at 3:11:53 AM
What many startups need to succeed is to be able to pivot/develop/repeat very quickly to find a product+market that makes money. If they don't find that, and most don't, the millions you talk about never come due. They also rarely have enough developers, so developer productivity in the short term is vital to that iteration speed. If that startup turns into Dropbox or Instagram, the millions you mention are round-off error on many billions. Easy business decision, and startups are first and foremost businesses.Some startups end up in between the two extremes above. I was at one of the Python-based ones that ended up in the middle. At $30M in annual revenue, Python was handling 100M unique monthly visitors on 15 cheap, circa-2010 servers. By the time we hit $1B in annual revenue, we had Spark for both heavy batch computation and streaming computation tasks, and Java for heavy online computational workloads (e.g., online ML inference). There were little bits of Scala, Clojure, Haskell, C++, and Rust here and there (with well over 1K developers, things creep in over the years). 90% of the company's code was still in Python and it worked well. Of course there were pain points, but there always are. At $1B in annual revenue, there was budget for investments to make things better (cleaning up architectural choices that hadn't kept up, adding static types to core things, scaling up tooling around package management and CI, etc.).
But a key to all this... the product that got to $30M (and eventually $1B+) looked nothing like what was pitched to initial investors. It was unlikely that enough things could have been tried to land on the thing that worked without excellent developer productivity early on. Engineering decisions are not only about technical concerns, they are also about the business itself.
by rented_mule
1/1/2026 at 11:49:51 PM
What language is “just as productive but isn't going to lock us into abysmal performance down the line”?What makes that language not strictly superior to Python?
by gcanyon
1/2/2026 at 9:50:08 PM
Typescript, C#, Go, Rust.I'd say they are almost strictly superior to Python, but there are some minor factors why you might still choose Python over those. E.g. arbitrary precision integers, or the REPL. Go is a bit tedious and Rust is harder to learn (but productive once you have).
But overall they would all be a better choice than Python. Yes even for startups who need to move fast.
by IshKebab
1/3/2026 at 11:19:53 PM
I say this out of genuine surprise, not judgment -- I never would have guessed that native Typescript is significantly faster than native Python. To be fair, I don't know if "significantly" is justified. I get that Typescript is typed (heh) and Python is not, but compared to my daily driver language (also not typed) Python is so much faster that I subconsciously think of typing as not being the major performance unlock. But I guess once you optimize the rest, typing is (nearly) the final boss of performance.by gcanyon
1/2/2026 at 2:11:57 AM
Loose typing makes you really fast at writing code, as long as you can keep all the details in your head. Python is great for smaller stuff. But crossed some threshold, the lack of a mechanism that has your back starts slowing you down.by nazgul17
1/2/2026 at 4:00:37 AM
Sure, my language of choice is more flexible than that: I can type put "test abc999 this" into x
add 1 to char 4 to 6 of word 2 of x
put x -- puts "test abc1000 this"
But I'm still curious -- what's the better language?
by gcanyon
1/2/2026 at 9:42:58 AM
If I made an app in python and in 10 years it grows so successful that it needs a $10m vertical scale or $5m rewrite, I wouldn't even complain.by anhner
1/2/2026 at 2:52:34 AM
I don't know a better open source language than Python. Java and C# are both better (platforms) but they come with that obvious corporate catch.by fud101
1/2/2026 at 6:44:13 PM
You can still get to use Scala, Kotlin, Clojure, F#, all with better performance than Python, and similar prototyping capabilities.by pjmlp
1/3/2026 at 1:37:25 AM
Those are non-mainstream languages, I think the point stands. You would need to prove the case for Scala or Kotlin tbh, Scala is hideously complex and Kotlin like Python suffers from becoming too bloated, accumulating features and syntax that are either not required or difficult to remember. Clojure and F# are nice and all but very niche.by fud101
1/3/2026 at 9:01:55 AM
Python being complex isn't an issue for beginners, apparently.Kotlin owns the mobile development market with 80% Android market share.
Scala was the AI before Python with Hadoop, Spark and friends.
Lisps might be niche, yet they were Python's flexibility, with machine code compilers, since 1958.
by pjmlp