Live data from Hacker News

Python 3.11 vs 3.10 performance

github.com

381–390 of 460 posts

Re: Python 3.11 vs 3.10 performance

#381

One of the biggest features I'm looking forward to is the more specific error messages. I can't tell you how much time I've wasted with cryptic errors that just point to a line that has a list comprehension or similar.

Not saying that there isn't room for improvement but I wouldn't call the Python error messages "cryptic". C++, on the other hand...

Re: Python 3.11 vs 3.10 performance

#382
post #353

Earlier quoted context omitted.

Or maybe keep things the way they are.If you really need performance python is not the language you should be looking for. Instead of breaking decades of code, maybe use a language like Go or Rust for performance instead.

I would have thought convincing people they’ll just have to use Go or Rust or Elixir would have been an easy sell around here. Turns out they just want a better Python.

>Turns out they just want a better Python.

That's Go. It gives actual types[1] and structs (so you dont have to wonder about dict, class, class with slots, dataclasses, pydantic, attrs, cattrs, marshmallow, etc). It removes exceptions and monkeypatching. It's async-first (a bit like gevent). It's inherently multicore. And you can package and distribute it without marking a pentagram on the ground and sacrificing an intern to Apep.

You just need to stop being friends with C FFI. Which is fine for web and sysadmin tools. For data science and ML/AI/DL, it's less ok.

[1] And the types are actually checked! I think a lot of people aren't really using python type checking given how slow it is and no one seems to complain. Or maybe everyone is using pyright and pyre and are satisfied with how slow these are.

Re: Python 3.11 vs 3.10 performance

#383

Earlier quoted context omitted.

Seems like just going with bash would be more straightforward?

Why would I want to subject myself to writing in a language like bash? Bash has many disadvantages compared to Python, Nim, Go, nearly anything that isn't brainfuck.

Yeah I mean it's pretty bad, but the upside is that it will run everywhere without having to install anything and there are lots and lots of answered questions out there if you run into issues. Which I doubt is true for Nim. Using niche stuff means you're on your own in terms of support.

And with how dependency happy everything is these days, I avoid trendy projects like the plague.

Re: Python 3.11 vs 3.10 performance

#384

Earlier quoted context omitted.

> you should not bother to write fast Python, just delegate all heavy lifting to optimized C/c++ and the likes Certainly that's something you can do, but unfortunately for Python it opens the door for languages like Julia, which are trying to say that you can have your cake and eat it too.

I like Julia but its easy to write slow julia unless you keep the performance tips in mind. Arrays are horribly slow, tuples are much faster, but having tuples be a multiple of 128 bytes adds 10% or more to speed. I honestly don't understand how much slower arrays are. Its like 30x or similar.

> I honestly don't understand how much slower arrays are. Its like 30x or similar.

In what context, under what operation? Depending on context, the difference makes sense and is what one would expect - tuples are immutable, with fixed size known at compile time, and stack-allocated; arrays are mutable, dynamic in size, and usually heap-allocated. That's why StaticArrays.jl [1] exists, for when you need something in between/the best of both worlds.

> I like Julia but its easy to write slow julia unless you keep the performance tips in mind.

I very much agree with this statement though. But following a very few basic ones like "avoid non-constant global variables", "look out for type instabilities", "use @views and @inbounds where it makes sense" gets you most of the way there, for eg. about 3-5x of the time a C program would take. Most of the rest of the tips on the Performance Tips [2] page are to squeeze out the last bits of performance, to go from 5x of C to near-C performance.

[1] https://github.com/JuliaArrays/StaticArrays.jl [2] https://docs.julialang.org/en/v1/manual/performance-tips/

Re: Python 3.11 vs 3.10 performance

#385

Earlier quoted context omitted.

Whenever I nest a list comprehension I feel dirty anyway, I wonder if a better error message will help solve something that is just hard to grasp sometimes.

All list comprehensions should error with message "FATAL PARSE ERROR: Will you really understand this in six months?"

Something like this I find ok (just a filter):

    [x for x in y if x is not z]
Sometimes though, facilitated by Jupyter's notebooks making executing as you build the code very easy, I create a beast like this:

    [os.path.join([x for x in y if x is not z]) + '/bin' for a in b if 'temp' not in a]
Yes this is fictional and probably contains an error but you get the point, you can filter lists of lists like this, but it's really unfriendly to anyone trying to understand it later.

Re: Python 3.11 vs 3.10 performance

#386
post #366

Earlier quoted context omitted.

Multiprocessing is fine, but the cost of starting another interpreter is pretty visible, so you need to create a pool, and it may not be an overall speedup if the run time is short. It takes more careful planning than async in JS?, say, or goroutines.

Yeah but for JS style async you'd use probably use an event loop in Python, not multi processing.

Yes. But, frankly, async is also simpler in JS than in Python: e.g. no need to start a reactor loop.

Re: Python 3.11 vs 3.10 performance

#387

Earlier quoted context omitted.

That quote has been thrown around every time in order to justify writing inefficient code and never optimizing it. Python is 10-1000x slower than C, but sure, let's keep using it because premature optimization is the root of all evil, as Knuth said. People really love to ignore the "premature" word in that quote. Instead, what he meant is that you should profile what part of the code is slow and focus on it first. Kn…

The thing is, when I see people using this quote, I don't see them generally using it to mean you should never optimize. I think people don't ignore the premature bit in general. Now, throwing this quote out there generally doesn't contribute to the conversation. But then, I think, neither does telling people to read the context when the context doesn't change the meaning of the quote.

Right but if they post just that part, they're probably heavily implying that now is not the time to optimize. I've seen way more people using it to argue that you shouldn't be focussing on performance at this time, than saying "sometimes you gotta focus on that 3% mentioned in the part of the quote that I deliberately omitted"

Re: Python 3.11 vs 3.10 performance

#388

One of the biggest features I'm looking forward to is the more specific error messages. I can't tell you how much time I've wasted with cryptic errors that just point to a line that has a list comprehension or similar.

Not saying that there isn't room for improvement but I wouldn't call the Python error messages "cryptic". C++, on the other hand...

I program in both C++ and Python every day and I'm fluent in both. I would prefer 10000 lines template instantiation backtraces every time to the average python error message.

Clang and GCC error messages have come a loooong way in the last 10 years or so and their quality is impressive.

To be fair, I'm currently stuck at python 3.6 ATM and I hear that python has also improved a lot since.

Re: Python 3.11 vs 3.10 performance

#389
post #336

Earlier quoted context omitted.

That’s bizarre, are they implemented as linked lists or something? Why would arrays be that slow?

They are not guaranteed to be contiguous, but they supposedly are if you specify a primative type and initialize them all at once. Tuples have a constant size, are contiguous, and immutable. So lots of optimization opportunity.

It is guaranteed to be contiguous. It might be an array of pointers if you put heap allocated objects in there (like an array of arrays). I think what you instead meant to say is that it's not guaranteed to be stored inline, which yes it is the case that it's only able to be stored inline if `Base.isbits(eltype(A))`, i.e. if it can deduce the bit length of the element type as constant and the objects are allocated to the stack. But of course that's just a requirement for storing values in an array even in C(++) (nice description here: https://stackoverflow.com/a/54654958/1544203), it's just a basic requirement due to having to know the memory size of what is being stored, and so it's not necessarily a limitation of Julia but of all languages.

Re: Python 3.11 vs 3.10 performance

#390

Earlier quoted context omitted.

Big list comprehensions cause confusion in many ways. KISS is crucial with them.

I agree. The rule of thumb I follow is that if the list comp doesn't fit on one line, whatever I'm doing is probably too complicated for a list comp.

But why? The only reason is that error messages are awful and intermediate values can't be named. There is in principle no reason why list comprehension need to be worse than straight line for loops. The deciding factor to chose betwee the two should be whether I'm writing something for side effects as opposed to for its value.
Post reply on HN