News for hackers. Stuff that matters.
Re:Python 3.11 vs 3.10 performance by amelius on Wednesday July 06, 2022 @12:08PM (#32002975)
"Premature optimization is the root of all evil."

-- Donald Knuth

Re:Python 3.11 vs 3.10 performance by GrayShade on Wednesday July 06, 2022 @12:15PM (#32003079)
You should probably read the full context around that quote, I'm sick and tired of everyone repeating it mindlessly:

https://softwareengineering.stackexchange.com/a/80092

> Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified.

Re:Python 3.11 vs 3.10 performance by winstonewert on Wednesday July 06, 2022 @12:19PM (#32003149)
> You should probably read the full context around that quote, I'm sick and tired of everyone repeating it mindlessly:

I'm confused. What do you think the context changes? At least as I read it, both the short form and full context convey the same idea.

Re:Python 3.11 vs 3.10 performance by GrayShade on Wednesday July 06, 2022 @12:27PM (#32003262)
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. Knuth didn't say you should be fine with 10-1000x slower code overall.

Re:Python 3.11 vs 3.10 performance by winstonewert on Wednesday July 06, 2022 @01:23PM (#32004041)
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.
Re:Python 3.11 vs 3.10 performance by smcl on Thursday July 07, 2022 @04:59AM (#32011535)
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 by winstonewert on Thursday July 07, 2022 @10:57AM (#32014920)
No, they don't deliberately omit the part of the quote. They are either unaware of that part of the quote or don't think it matters to the point they are making.

Yes, if you quote Knuth here (whether the short quote or a longer version) you are probably responding to someone whom you believe is engaged in premature optimization.

It remains that the person quoting Knuth isn't claiming that there isn't such a thing as justified optimization. As such, pointing to the context doesn't really add to the conversation. (Nor does a thoughtless quote of Knuth either)

Re:Python 3.11 vs 3.10 performance by smcl on Thursday July 07, 2022 @12:41PM (#32016246)
I dunno, guess it's hard to say given we're talking about our own subjective experiences. I completely believe there are people who just know the "premature optimization is the root of all evil" part and love to use it because quoting Knuth makes them sound smart. And I'm sure there are also people know it all and who quote that part in isolation (and in good faith) because they want to emphasise that they believe you're jumping the gun on optimization.

But either way I think the original statement is so uncontroversial and common-sense I actually think it doesn't help any argument unless you're talking to an absolutely clueless dunce or unless you're dealing with someone who somehow believes every optimization is premature.

Re:Python 3.11 vs 3.10 performance by bshipp on Wednesday July 06, 2022 @01:22PM (#32004026)
You certainly can accept that slowdown if the total program run-time remains within acceptable limits and the use of a rapid prototyping language reduces development time. There are times when doing computationally heavy, long-running processes where speed is important, but if the 1000x speedup is not noticeable to the user than is it really a good use of development time to convert that to a more optimized language?

As was said, profile, find user-impacting bottlenecks, and then optimize.

Re:Python 3.11 vs 3.10 performance by winstonewert on Wednesday July 06, 2022 @01:27PM (#32004091)
I would note that the choice of programming language is a bit different. Projects are pretty much locked into that choice. You've got to decide upfront whether the trade off in a rapid prototyping language is good or not, not wait until you've written the project and then profile it.
Re:Python 3.11 vs 3.10 performance by dragonwriter on Wednesday July 06, 2022 @07:34PM (#32008205)
> Projects are pretty much locked into that choice.

But, they aren't.

I mean, profile, identify critical components, and rewrite in C (or some other low-level language) for performance is a normal thing for most scripting languages.

> You've got to decide upfront whether the trade off in a rapid prototyping language is good or not, not wait until you've written the project and then profile it.

No, you absolutely don't.

Re:Python 3.11 vs 3.10 performance by winstonewert on Wednesday July 06, 2022 @09:48PM (#32009072)
Yes, it true, if you use Python you can rewrite portions in C to get improved performance. But my point was rather that you couldn't later decide you should have written the entire project in another language like Rust or C++ or Java or Go. You've got the make decision about your primary language up-front.

Or to look at it another way: Python with C extensions is effectively another language. You have to consider it as an option along with Pure Python, Rust, Go, C++, Java, FORTRAN, or what have you. Each language has different trade-offs in development time vs performance.

Re:Python 3.11 vs 3.10 performance by bshipp on Wednesday July 06, 2022 @01:32PM (#32004150)
Certainly, but Python is flexible enough that it readily works with other binaries. If a specific function is slowing down the whole project, an alternate implementation of that function in another language can smooth over that performance hurdle. The nice thing about Python is that it is quite happy interacting with C or go or Fortran libraries to do some of the heavy lifting.
Re:Python 3.11 vs 3.10 performance by wzdd on Wednesday July 06, 2022 @01:58PM (#32004521)
The quote at least contextualises "premature". As it is, premature optimisation is by definition inappropriate -- that's what "premature" means. The context:

a) gives a rule-of-thumb estimate of how much optimisation to do (maybe 3% of all opportunities);

b) explains that non-premature opimisation is not just not the root of all evil but actually a good thing to do; and

c) gives some information about how to do non-premature optimisation, by carefully identifying performance bottlenecks after the unoptimised code has been written.

I agree with GP that unless we know what Knuth meant by "premature" it is tempting to use this quote to justify too little optimisation.

Re:Python 3.11 vs 3.10 performance by DasIch on Wednesday July 06, 2022 @12:31PM (#32003327)
I agree with you, the context changes nothing (and I upvoted you for this reason). However programming languages and infrastructure pieces like this are a bit special, in that optimizations here are almost never premature.

  * Some of the many applications relying on these pieces, could almost certainly use the speedup and for those it wouldn't be premature
  * The return of investment is massive due to the scale
  * There are tremendous productivity gains by increasing the performance baseline because that reduces the time people have to spend optimizing applications
This is very different from applications where you can probably define performance objectives and define much more clearly what is and isn't premature.
Re:Python 3.11 vs 3.10 performance by winstonewert on Wednesday July 06, 2022 @01:25PM (#32004062)
I don't know about that. Even with your programming language/infrastructure you still want to identify the slow bits and optimize those. At the end of the day, you only have a certain amount of bandwith for optimization, and you want to use that where you'll get the biggest bang for you buck.
Re:Python 3.11 vs 3.10 performance by maxbond on Wednesday July 06, 2022 @12:21PM (#32003167)
This certainly does not mean, "tolerate absurd levels of technical debt, and only ever think about performance in retrospect."
Re:Python 3.11 vs 3.10 performance by dragonwriter on Wednesday July 06, 2022 @12:24PM (#32003213)
Python was meeting needs well enough to be one of, if not the single, most popular language for a considerable time and continuing to expand and become dominant in new application domains while languages that focussed more heavily on performance rose and fell.

And it's got commercial interests willing to throw money at performance now because of that.

Seems like the Python community, whether as top-down strategy or emergent aggregate of grassroots decisions made the right choices here.

Re:Python 3.11 vs 3.10 performance by maxbond on Wednesday July 06, 2022 @04:12PM (#32006189)
Python had strengths that drove it's adoption, namely that it introduced new ideas about a language's accessibility and readability. I'm not sure it was ever really meeting the needs of application developers. People have been upset about Python performance and how painful it is to write concurrent code for a long time. The innovations in accessibility and readability have been recognized as valuable - and adopted by other languages (Go comes to mind). More recently, it seems like Python is playing catch-up, bringing in innovations from other languages that have become the norm, such as asyncio, typing, even match statements.

Languages don't succeed on their technical merit. They succeed by being good enough to gain traction, after which it is more about market forces. People choose Python for it's great ecosystem and the availability of developers, and they accept the price they pay in performance. But that doesn't imply that performance wasn't an issue in the past, or that Python couldn't have been even more successful if it had been more performant.

And to be clear, I use Python every day, and I deeply appreciate the work that's been put into 3.10 and 3.11, as well as the decades prior. I'm not interested in prosecuting the decisions about priorities that were made in the past. But I do think there are lessons to be learned there.

Re:Python 3.11 vs 3.10 performance by lmm on Wednesday July 06, 2022 @06:32PM (#32007727)
> tolerate absurd levels of technical debt

In my experience it's far more common for "optimizations" to be technical debt than the absence of them.

> only ever think about performance in retrospect

From the extra context it pretty much does mean that. "but only after that code has been identified" - 99.999% of programmers who think they can identify performance bottlenecks other than in retrospect are wrong, IME.

Re:Python 3.11 vs 3.10 performance by maxbond on Thursday July 07, 2022 @12:43PM (#32016278)
Well it's entirely possible that Knuth and I disagree here, but if you architect an application without thinking about performance, you're likely going to make regrettable decisions that you won't be able to reverse.

It is not possible to predict bottlenecks in computation, no. But the implications of putting global state behind a mutex in a concurrent application should be clear to the programmer, and they should think seriously before making a choice like that. If you think of a different way to do that while the code is still being written, you'll avoid trapping yourself in an irreversible decision.

Re:Python 3.11 vs 3.10 performance by chaosfox on Wednesday July 06, 2022 @12:32PM (#32003345)
python isn't premature. python is more than 30 years old now, python 3 was released more than 10 years go.
Re:Python 3.11 vs 3.10 performance by bshipp on Wednesday July 06, 2022 @01:24PM (#32004053)
It's been at least 5 years since I read an angry post about the 2 to 3 version change, so I guess it's finally been accepted by the community.
Re:Python 3.11 vs 3.10 performance by neysofu on Wednesday July 06, 2022 @12:55PM (#32003658)
i would say this quote does not apply here. VM implementations are in the infamous 3% Donald Knuth is warning us about.