logoalt Hacker News

thundergolferyesterday at 7:11 PM5 repliesview on HN

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


Replies

NoteyComplexitytoday at 12:47 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.

Scubabear68yesterday at 11:21 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.

show 1 reply
i_am_a_peasantyesterday at 8:17 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.

oofbeyyesterday at 7:21 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.

show 1 reply
nutjob2yesterday at 7:21 PM

> A lot of important and large codebases were grown and maintained in Python

How does this happen? Is it just inertia that cause people to write large systems in a essentially type free, interpreted scripting language?

show 7 replies