News for hackers. Stuff that matters.
Re:“Clean” Code, Horrible Performance by mquander on Tuesday February 28, 2023 @04:18PM (#34974993)
> Look, most modern software is spending 99.9% of the time waiting for user input, and 0.1% of the time actually calculating something. If you're writing a AAA video game, or high performance calculation software then sure, go crazy, get those improvements.

That's really not even close to true. Loading random websites frequently costs multiple seconds worth of local processing time, and indeed, that's often because of the exact kind of overabstraction that this article criticizes (e.g. people use React and then design React component hierarchies that seem "conceptually clean" instead of ones that perform a rendering strategy that makes sense.)

Re:“Clean” Code, Horrible Performance by commandlinefan on Tuesday February 28, 2023 @04:41PM (#34975256)
Well, you can make things run even faster by hand-coding it in assembler... but performance isn't the reason we use high level languages. I agree with you that ignoring performance characteristics in favor of speed-to-market is an awful and pervasive practice in modern software development, but the linked article isn't talking about or making that case at all. He's saying that he can make his own custom object oriented C language that runs faster than C++ itself, but that's not news - people were saying that in 1995 (at least). The maintainability hit isn't worth it.
Re:“Clean” Code, Horrible Performance by pmarin on Tuesday February 28, 2023 @05:24PM (#34975791)
This is not his own custom object oriented C language, this is just a very well known idiom for implementing polymorphic functions in C.
Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:57PM (#34978595)
It's not really possible to write hand-coded assembler that's faster anymore. C/C++ compilers have deep knowledge of architecture-specific instruction pipelines that allow them to schedule instructions more accurately than any human could.

My most recent misadventure: trying to write hand-coded ARM Neon assembler, and/or C++ code with neon intrinsics to optimize a piece of real-time audio effect code. The clear performance winner: plain C++ with no intrinsics, but tweaked to allow auto-vectorization (plus judicious use of the __restrict modifier for a small but significant boost). GCC produced code that had better instruction scheduling than I could (but not for the NEON intrinsics, oddly). And as an added bonus, the same plain-old C++ code generates AVX vectorization on MSVC without modifications! (MSVC also supports __restrict until the C++ standards committee gets their act together to adopt the eminently necessary C99 restrict keyword).

Re:“Clean” Code, Horrible Performance by DeathArrow on Wednesday March 01, 2023 @05:14AM (#34980690)
It is. I witnessed it many times on Code Golf substack.
Re:“Clean” Code, Horrible Performance by pg314 on Wednesday March 01, 2023 @06:25AM (#34981140)
>It's not really possible to write hand-coded assembler that's faster anymore.

That is wrong. Just because you didn’t succeed in writing faster code in one case, doesn’t mean it’s impossible. See e.g. [1] on why the Lua vm is written in assembly. It’s from 2011 but not much has changed in the meantime.

[1] http://lua-users.org/lists/lua-l/2011-02/msg00742.html

Re:“Clean” Code, Horrible Performance by mabbo on Tuesday February 28, 2023 @04:41PM (#34975248)
I don't disagree that the balance is shifting towards "why is this taking so long". There's ebbs and flows in that ecosystem.

But overall, I think you overestimate how much time you spend loading the website and how much time it's just sitting there, mostly idle.

And in the end, as long as it's fast enough that users don't stop using the site/webapp/program/whatever, then it's fine, imho. When it becomes too slow, the developers will be asked to improve performance. Because in the end, economics is the driver, not performance.

Re:“Clean” Code, Horrible Performance by jstimpfle on Tuesday February 28, 2023 @04:44PM (#34975284)
And depending on what you do, economics will let performance decide who wins. Git is probably one example. A different example, have you ever compared battery lifes of smartphones before buying one?
Re:“Clean” Code, Horrible Performance by ilyt on Tuesday February 28, 2023 @04:53PM (#34975406)
> But overall, I think you overestimate how much time you spend loading the website and how much time it's just sitting there, mostly idle.

reading the website is productive. Waiting on it to load is not.

I'd rather have app burn a whole core whole time if it cut 1s off load time when clicking something.

Re:“Clean” Code, Horrible Performance by tharkun__ on Tuesday February 28, 2023 @09:11PM (#34977884)
I think the point would be: what if instead of using a whole core and it takes 2000ms to load because it is essentially "spinning its wheels" it would only use half a core and it takes 50ms?

2s you notice as a user. 50ms you won't. In fact even 500ms you won't notice too much but we are getting close to where optimization will be noticeable to a user.

Re:“Clean” Code, Horrible Performance by sirmarksalot on Tuesday February 28, 2023 @08:18PM (#34977483)
As an end user, I would prefer to live in a world where I don't have to wait for software to respond. If forced to, I would also continue to use software where I do have to wait. Your argument that economics will dictate the best solution and lead to a happy balance doesn't work. It will tend towards a borderline tolerable world, where your product only has to be better than the other guy's.

This is separate from the discussion about tradeoffs between flexible design patterns and low-level performance.

Re:“Clean” Code, Horrible Performance by raspberry1337 on Wednesday March 01, 2023 @06:05AM (#34981017)
He never said "happy", he said its fine. Meaning its fine that you have to live in a world where you have to wait for some software to respond, even if you would prefer not to. If you are happy in such a (horrible || ok) world is up to you.
Re:“Clean” Code, Horrible Performance by jimbokun on Tuesday February 28, 2023 @09:57PM (#34978213)
This is a few years old, but gives a sense of how much money might be left on the table due to a slow loading web page:

https://www.marketingdive.com/news/google-53-of-mobile-users...

Re:“Clean” Code, Horrible Performance by PragmaticPulp on Tuesday February 28, 2023 @04:31PM (#34975131)
> That's really not even close to true. Loading random websites frequently costs multiple seconds worth of local processing time

Unless we’re talking about specific compute-intensive websites, this is almost certainly network loading latency.

Modern web browsers are very fast. Moderns CPUs are very fast. Common, random websites aren’t churning through “multiple seconds” of CPU time just to render.

Re:“Clean” Code, Horrible Performance by fvdessen on Tuesday February 28, 2023 @05:02PM (#34975554)
I once optimised a SPA app that had to be really fast for usability reasons (industrial use), I replaced all the 'high level' JS patterns such as map, filter, and frontend framework things to use just if else and for loops and native dom manipulation, and it ended up more than 10x faster, each click would update the app in one frame, it was very noticeable. So yes CPU cycles do matter for websites, even with modern hardware. However the code was more verbose and needed a lot more technical know-how to understand and maintain.
Re:“Clean” Code, Horrible Performance by Veliladon on Tuesday February 28, 2023 @06:22PM (#34976388)
Yep. In Rust land for instance it'd get compiled down to a for loop and be ridiculously fast. Every time you do a .map or a .filter in JS though it gets abstracted down to a function that makes an allocation for the ENTIRE ARRAY and then copies the entire array into that new array doing whatever you asked to data. The JS VM might be able to optimize some of it away but the abstraction is awful.

So if you were to manually run a for loop over an array instead of iterating through it I'm not surprised you got an order of magnitude faster performance.

Re:“Clean” Code, Horrible Performance by gardenhedge on Tuesday February 28, 2023 @06:54PM (#34976670)
I'd be interested in a blog post on this. Why is JS map so much slower than a for loop?
Re:“Clean” Code, Horrible Performance by Veliladon on Tuesday February 28, 2023 @08:19PM (#34977500)
So normally when you do a bunch of patterns of .filter(), and/or .map(), and/or .reduce() on an array in most other languages the compiler will normally iterate through the elements doing whatever you requested at each element. No allocations, one quick trip through the entire working set, cache locality works no matter how big the set is.

In JavaScript on the other hand it handles the abstraction by constructing a separate function for each pattern you use. In those functions it allocates an array the same size as the working set, iterates through each element, then returns the new array. If you're doing multiple operations at once this means that you have to have multiple allocations and multiple iterations through the entire working set.

Because it's doing an allocations it's basically doing an extra memcpy for each additional pattern past one which is a giant slowdown. Then if the working set is too big for the L2 cache it needs to be reloaded from L3 each loop. If the working set is too big for L3 then it needs to reload from main memory EACH TIME.

If you wanted to implement patterns as slow as molasses I can think of no better way than to sugar it out like JavaScript did.

Re:“Clean” Code, Horrible Performance by jimbokun on Tuesday February 28, 2023 @10:02PM (#34978250)
Interesting. Is there something about JS semantics that prevents JS engine writers from better optimizing that pattern?
Re:“Clean” Code, Horrible Performance by Veliladon on Wednesday March 01, 2023 @12:46AM (#34979189)
Short answer: JavaScript arrays are sparse and untyped.
Re:“Clean” Code, Horrible Performance by david2ndaccount on Tuesday February 28, 2023 @08:33PM (#34977609)
Approximately, the slowest thing you can do in a program is memory allocation (and garbage collection is even slower). JS map allocates an entire new array.
Re:“Clean” Code, Horrible Performance by jimbokun on Tuesday February 28, 2023 @09:59PM (#34978232)
Interesting that the speed up you saw was very similar to what the author got from the same kind of changes in C++.
Re:“Clean” Code, Horrible Performance by gary_0 on Tuesday February 28, 2023 @05:05PM (#34975585)
I just loaded cnn.com while looking at the CPU utilization graph: 50% use of my 8 logical cores at 4.5GHz for the better part of a second. So no, it's not just network latency. Doing multiple parallel network requests, parsing, doing layout and applying styles, running scripts, decoding media... a modern website and browser devours CPU time.
Re:“Clean” Code, Horrible Performance by jiggawatts on Tuesday February 28, 2023 @05:33PM (#34975880)
Jira cloud famously takes 30-60 seconds on even a fairly high-end laptop, which is just staggering. I can install an entire operating system into a virtual machine in that time.
Re:“Clean” Code, Horrible Performance by PragmaticPulp on Tuesday February 28, 2023 @09:47PM (#34978156)
> Jira cloud famously takes 30-60 seconds on even a fairly high-end laptop,

I use Jira every day and, no, it does not take 30-60 seconds to load a page.

The hyperbole in this comment section is something else. Either that or people are using 15 year old computers to browse the web.

Re:“Clean” Code, Horrible Performance by zweifuss on Tuesday February 28, 2023 @10:37PM (#34978473)
I see 30-seconds delays in a vanilla project on Jira cloud sometimes. Hardware was expensive in 2019.
Re:“Clean” Code, Horrible Performance by gowld on Tuesday February 28, 2023 @05:26PM (#34975814)
AdBlocker on or off?
Re:“Clean” Code, Horrible Performance by smoyer on Tuesday February 28, 2023 @05:27PM (#34975826)
lite.cnn.com
Re:“Clean” Code, Horrible Performance by datavirtue on Tuesday February 28, 2023 @05:14PM (#34975672)
So those who visit Fox and CNN are helping to destroy the planet. Or is it the developers fault? Can't be the developers.
Re:“Clean” Code, Horrible Performance by replygirl on Tuesday February 28, 2023 @05:43PM (#34975986)
one of them must be to blame! readers and publishing engineers famously sit atop corporate decision-making hierarchies, and no one else in a mass media enterprise ever did anything wrong, certainly not before the web was a thing
Re:“Clean” Code, Horrible Performance by pugz on Tuesday February 28, 2023 @11:43PM (#34978856)
I was about to dispute what you said, but I realised I was running uBlock origin. What machine and browser are you using? I just used Chrome (on MacOS using an M1 Pro CPU) to run a performance profile and loading cnn.com took the following:

- Loading: 29ms with uBlock vs 42ms without

- Scripting: 548ms vs 1850ms (!!)

- Rendering: 42ms vs 105ms

- Painting: 8ms vs 29ms

- System: 216ms vs 295ms

- Idle: 460ms vs 8707ms

Holy shit, advertising and trackers are absolute resource hogs.

Re:“Clean” Code, Horrible Performance by gratitoad on Tuesday February 28, 2023 @07:09PM (#34976837)
This might hold true if you’re talking about desktop browsers, but it’s a different story on mobile, particularly in rapidly growing emerging markets. Both network latency and large JS payloads dramatically affect user experience on low powered devices, and if UX isn’t compelling enough, there have been plenty of studies showing the real financial costs of slow web pages for businesses that depend those websites to bring in customers.

I’ve personally spent many hours doing performance analysis, triage and remediation on websites built using modern tech stacks that had inadvertently exchanged UX for DX. Too much JS sent over the wire can definitely tie up the browser’s main thread for whole seconds even on desktop, though in my experience it’s much more common on mobile. This situation can be difficult to correct depending on the abstractions, organization and overall architecture you chose early on, and code-spitting and dead code elimination won’t always fix what’s broken.

Re:“Clean” Code, Horrible Performance by rodrigobellusci on Tuesday February 28, 2023 @04:33PM (#34975154)
Since you bring up React in your example, which framework should one use to build better performing web apps?

I know React tends to lack in both dev UX and performance (at least in my exp). Personally I've taken a look at Svelte and Solid, and liked them both. I haven't had the chance to build anything larger than a toy app, though.

Re:“Clean” Code, Horrible Performance by antoineMoPa on Tuesday February 28, 2023 @04:38PM (#34975221)
Vue could also be an option, but I personally want to learn some Solid, as I see it could be preferred by the current mass of React frontend developers, more than Svelte and Vue. The syntax and philosophy of Solid looks closer to React, while having a stronger focus on performance.
Re:“Clean” Code, Horrible Performance by bcrosby95 on Tuesday February 28, 2023 @06:07PM (#34976218)
Okay, I'll bite: does Vue perform better than React? Your post makes no mention of this, I don't know if it does, and offering it as an alternative due to performance reasons, without knowing this, seems a tad premature.
Re:“Clean” Code, Horrible Performance by antoineMoPa on Wednesday March 01, 2023 @09:12AM (#34982577)
In my personal experience, the Vue apps I've worked on have been snappier. There are some fast React apps out there, but I think a lot of work goes into optimizing React apps, versus Vue being pretty fast by default.

When react introduced hooks, it was fun for a while, but then we discovered the frequent re-render issues and had to change the way we think when building components and refactor old components. We have to manually wrap components in useMemo. This is the kind of things Vue has avoided me so far and React let me down. React relies on running all render methods instead of doing granular updates, I think this hurts performance. Vue listens to property changes and can perform granular updates.

Re:“Clean” Code, Horrible Performance by antoineMoPa on Friday March 03, 2023 @06:16PM (#35016308)
I kind of want to amend that! I discovered today that maybe there is hope with granular update libraries such as Jotai, @preact/signals-react and recoiljs.
Re:“Clean” Code, Horrible Performance by jay_kyburz on Tuesday February 28, 2023 @04:39PM (#34975229)
You should just try working directly in HTML.
Re:“Clean” Code, Horrible Performance by eropple on Tuesday February 28, 2023 @05:14PM (#34975675)
I look forward to returning to the days where everybody wrote their own slightly-to-significantly-wrong state management tooling while being distracted by the minutiae of DOM wrangling. That was a good time.

(It was not. It was why I stopped doing frontend work.)

Re:“Clean” Code, Horrible Performance by nottorp on Wednesday March 01, 2023 @03:37AM (#34980097)
Perhaps ... it's the underlying platform's fault?
Re:“Clean” Code, Horrible Performance by eropple on Wednesday March 01, 2023 @11:13AM (#34983948)
Yeah, but it's the one we've got. As much as people want to sniff about it, that bell isn't getting un-rung for more, perhaps most, use cases--on balance things are better where we're at now.
Re:“Clean” Code, Horrible Performance by rodrigobellusci on Sunday March 05, 2023 @09:14PM (#35036728)
For sure, I've been trying to cut down on dependencies and JS where possible.

I'm curious to give WebComponents a try as well.

Re:“Clean” Code, Horrible Performance by datavirtue on Tuesday February 28, 2023 @05:19PM (#34975730)
I recently tried Vue 3 at a startup for a new app. A few days after starting it I rewrote a personal Svelte app in Vue 3 since I found it so fluid (Composition API w/ script setup). I was liking Svelte before that.
Re:“Clean” Code, Horrible Performance by rodrigobellusci on Sunday March 05, 2023 @09:09PM (#35036694)
Oh that's interesting! Will definitely keep Vue 3 in mind for future then.
Re:“Clean” Code, Horrible Performance by DeathArrow on Wednesday March 01, 2023 @05:17AM (#34980708)
We are using Vue instead of React reasons being both performance and simplicity.
Re:“Clean” Code, Horrible Performance by onion2k on Tuesday February 28, 2023 @04:51PM (#34975371)
For what it's worth, less than 4% of websites use React (approximately 4% use any JS framework) . If you believe the web is slow because of React you are wrong. It's not even due to JS.
Re:“Clean” Code, Horrible Performance by valzam on Tuesday February 28, 2023 @05:00PM (#34975531)
4% of what? I would wager a guess that close to 100% of Alexa top 1000 websites us a JS framework and a significant portion of that something heavy like React or Angular.
Re:“Clean” Code, Horrible Performance by gratitoad on Tuesday February 28, 2023 @04:59PM (#34975525)
I’m curious, where do you get those numbers from? Those are shockingly low numbers and don’t align with my observations, but I also don’t have hard figures to back them up.
Re:“Clean” Code, Horrible Performance by ramesh31 on Tuesday February 28, 2023 @05:23PM (#34975781)
>It's not even due to JS.

Oh it definitely is. But no single framework (or frameworks) are to blame. It's the CMS. The thing that allows every Tom, Dick, and Harry at the company to drop their little snippet for this or that which adds up to a mountain of garbage over time, half of which is disused or forgotten.

Re:“Clean” Code, Horrible Performance by jimbokun on Tuesday February 28, 2023 @10:05PM (#34978269)
Is that weighted for the traffic those web sites receive?

It could be that most of the traffic is served by websites using heavyweight frameworks, but the long tail of low traffic websites use them rarely.

Re:“Clean” Code, Horrible Performance by wellanyway on Thursday March 02, 2023 @04:49AM (#34993900)
> It's not even due to JS.

Do enlighten us then, what is it due to?

Re:“Clean” Code, Horrible Performance by simplotek on Tuesday February 28, 2023 @04:52PM (#34975385)
> That's really not even close to true. Loading random websites frequently costs multiple seconds worth of (...)

You attempted to present an argument that's a textbook example of an hyperbolic fallacy.

There are worlds of difference between "this code does not sit in a hot path" and "let's spend multiple seconds of local processing time".

This blend of specious reasoning is the reason why the first rule of software optimization is "don't". Proponents of mindlessly going about the 1% edge cases fail to understand that the whole world is comprised of the 99% of cases where shaving off that millisecond buys you absolutely nothing, with a tradeoff of producing unmaintainable code.

The truth of the matter is that in 99% of the cases there is absolutely no good reason to run after these relatively large performance improvements if in the end the user notices absolutely nothing. Moreso if you're writing async code that stays far away from any sort of hot path.

Re:“Clean” Code, Horrible Performance by heisenbit on Tuesday February 28, 2023 @05:08PM (#34975608)
How does an organization which has been built on 99% not doing optimization recognize the one percent where it matters a lot?
Re:“Clean” Code, Horrible Performance by eropple on Tuesday February 28, 2023 @05:13PM (#34975661)
In my experience: a profiler, usually. Just because I can throw down a lot of code quickly doesn't mean I don't have the tools to analyze code when I go "hmm, that seems slow".
Re:“Clean” Code, Horrible Performance by incrudible on Wednesday March 01, 2023 @04:27AM (#34980375)
That works for big hotspots, but not for the tiny papercuts that make every little thing 10x slower.
Re:“Clean” Code, Horrible Performance by eropple on Thursday March 02, 2023 @10:33AM (#34996909)
Sure. That's a tradeoff you consciously make to get the thing out the door. That's what technical debt is. You pay it down later. (Or you go bankrupt and it doesn't matter anymore.)
Re:“Clean” Code, Horrible Performance by incrudible on Friday March 03, 2023 @03:40PM (#35014704)
The blog post challenges the assumption that the slower version is any way improving productivity. At least for the given example, I agree.
Re:“Clean” Code, Horrible Performance by Turskarama on Tuesday February 28, 2023 @06:05PM (#34976197)
Testing, do you not do testing? Use the software. If it seems slow drill down and find the critical path and optimize it.
Re:“Clean” Code, Horrible Performance by yuliyp on Tuesday February 28, 2023 @06:44PM (#34976589)
Testing is often not enough. Developers might have a few test cases with a few records, or a few other users. Real users might do more with it, and things which perform fine in testing suddenly turn into real performance bottlenecks when you're loading an order list with a thousand entries in it instead of two.
Re:“Clean” Code, Horrible Performance by Turskarama on Tuesday February 28, 2023 @10:01PM (#34978248)
When I said testing that includes integration testing, not just unit tests. We do this exact thing with queries that are known to be complex, run them against databases the same size and complexity as real production databases. It's not hard.
Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:40PM (#34978496)
Building representative databases is not straightforward.

If you're lucky enough to eat your own dogfood, run unit tests against a copy(!) of your in-house database. A utility to anonymize the data was a fairly significant investment, but absolutely worth it in the long run. Being able to run and monitor benchmark unit tests for selected critical operations on enterprise-scale test data as part of the continuous-build process: fabulous!

Re:“Clean” Code, Horrible Performance by julik on Tuesday February 28, 2023 @06:23PM (#34976391)
By someone presenting plausible evidence that not having that 1% optimised costs the organization money/business, and leadership that would listen
Re:“Clean” Code, Horrible Performance by saagarjha on Tuesday February 28, 2023 @06:26PM (#34976421)
In any organization it generally pays off to have most people have a basic knowledge of a subject and then hire domain experts to drive most of the impact. For security, for example, this typically manifests as having very general "best practices" for most developers to follow and then a small team that handles anything that requires advanced understanding of the area.

How this typically works with performance is very similar, with a small team working to identify problematic areas where optimization would drive the highest impact, and the rest of the organization keeping performance in mind but not otherwise concerned with it in their day-to-day work.

Re:“Clean” Code, Horrible Performance by simplotek on Tuesday February 28, 2023 @07:28PM (#34977046)
> How does an organization which has been built on 99% not doing optimization recognize the one percent where it matters a lot?

If you can't recognize the percent where it matters a lot, clearly that percent does not exist and you're bothering about nothing.

I see a lot of talk about the importance of tuning Formula 1 cars in a world where everyone drives ford fiestas.

Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:24PM (#34978383)
Profiling. If you're not profiling, you're completely wasting your time. The 1% is almost never where you think it is.

And when you do identify the 1%, you need to be testing optimizations with a profiler constantly while optimizing. Profile. Do some optimization. Profile again. Roll back if not successful. Repeat until done. It's impossible to optimize well if you're not doing profiling.

The ultimate tools would be either Intel's profiling tools, or ARM's profiling suite (both very expensive). But MSVC and GCC do a fantastic job of scheduling instructions to avoid pipeline stalls these days, so these deep profiling tools are unlikely to gain more than 2 or 3% performance increases these days. (Worthwhile pretty much only if you're writing GPU drivers for NVidia or AMD).

Taken as a given that 100% of your code is at least algorithmically correct in the first place. (Appropriately better than O(N^2) whenever possible).

- Former writer of graphics drivers, currently audio DSP engineer.

Re:“Clean” Code, Horrible Performance by anonymoushn on Tuesday February 28, 2023 @11:18PM (#34978701)
A hash table that accesses a minimum of 2 cache lines per query can be algorithmically correct and also admit a 100% speedup.
Re:“Clean” Code, Horrible Performance by themulticaster on Wednesday March 01, 2023 @02:29PM (#34987080)
I'm not familiar with how it compares to ARM/Intel's profiling tools, but I found the Linux perf suite to be very capable (though limited to Linux obviously). And Hotspot [1] allows effortless profile visualization using flame graphs, including some very interesting features such as off-CPU time profiling [2]. "perf record" coupled with Hotspot forms a very smooth edit-compile-profile cycle.

[1] https://github.com/KDAB/hotspot

[2] https://github.com/KDAB/hotspot#off-cpu-profiling

Re:“Clean” Code, Horrible Performance by rerdavies on Thursday March 02, 2023 @02:00AM (#34992913)
Agreed. Linux perf tools are perfectly acceptable for all but the most ultra-extreme optimization tasks.

VTune allows you to determine where pipeline stalls are occurring at the instruction level (for that last 2 or 3% gain in performance). I haven't worked with ARM profilers (way out of my price range), but I assume, given the exorbitant price, they provide the same sort of in-depth analysis. Probably a handful of people on the planet that need that kind of in-depth analysis.

Re:“Clean” Code, Horrible Performance by loup-vaillant on Tuesday February 28, 2023 @05:53PM (#34976080)
I realised when I implemented EdDSA for Monocypher that optimisations compound. When I got rid of a bottleneck, I noticed that another part of the code was the new bottleneck, and some of the optimisations compounded multiplicatively. It took many changes before I finally started to hit diminishing returns and stop. All while restricting myself to standard C99, and trying fairly hard not to spend too many lines of code on this.

My point being, if most of the program is slowed down by a slew of wasted CPU cycles (costly abstractions, slow interpreted language…), there's a good chance what should have been obvious bottlenecks get drowned in a see of underperformance. They're harder to spot, and fixing them doesn't change much.

So before you even get to actual optimisation, your program should be fast enough that actual optimisations have a real impact. And yes, actual optimisation should be done quite rarely. But first, we need to make sure our programs aren't as slow as molasses. See https://www.youtube.com/watch?v=pgoetgxecw8

Re:“Clean” Code, Horrible Performance by simplotek on Tuesday February 28, 2023 @07:25PM (#34977014)
> I realised when I implemented EdDSA for Monocypher that optimisations compound.

I feel you're missing the whole point.

It's immaterial whether anyone can get to optimizations that compound multiplicatively. The whole point is that halving something that costs nothing earns you nothing. That's the whole point. Go ahead and shave off that millisecond. Will anyone actually notice whether you add or remove that penalty? Odds are, not at all.

Re:“Clean” Code, Horrible Performance by loup-vaillant on Tuesday February 28, 2023 @07:59PM (#34977314)
People did notice. Quite a few happy users are glad signature verification took less than a second instead of more than 3. Or 30, if you compare to some of the alternatives. Others love the fact it uses 2KB of stack space instead of 5.

Monocypher's speed was actually an important component in its success in the embedded market, even though I didn't explicitly target it initially (I was lucky my portability driven decisions made it a good fit there).

Re:“Clean” Code, Horrible Performance by tharkun__ on Tuesday February 28, 2023 @09:05PM (#34977836)
Not your parent but I think that is exactly the point lots of people here are making.

There definitely are niches where there are quite a few performance optimization opportunities that users do care about.

In your example making something a user is actively waiting for go from 3 seconds to less than one is a great optimization target. What is not a great optimization target is making something the user is actively waiting for and that takes 30ms take 25ms instead. That's wasted money on developer time.

If your "user" is a developer of embedded software with memory constraints and using your library leaves them more room that's awesome. If your user was someone using the library on a general purpose computing device with loads of memory then the 2 vs. 5 does nothing.

Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:05PM (#34978271)
You need to do some research on how to get modern C/C++ compilers to vectorize.;-) No assembly required, and not that hard to restructure code. (But MUCH easier in C++).
Re:“Clean” Code, Horrible Performance by anonymoushn on Tuesday February 28, 2023 @11:16PM (#34978692)
So far it seems like if you have some parsing or formatting task that can be trivially vectorized, the compiler will never do that, and you absolutely must use intrinsics.
Re:“Clean” Code, Horrible Performance by loup-vaillant on Wednesday March 01, 2023 @02:58AM (#34979856)
I tried auto-vectorisation, and it worked pretty well. But the code became just as big as using intrinsics would have (that with explicitly unrolling loops and rearranging things in memory), and intrinsics generated code that was easily 35% faster.

I decided not put it off for later, and keep things simple for now.

Re:“Clean” Code, Horrible Performance by mquander on Tuesday February 28, 2023 @06:13PM (#34976280)
The subfields of programming I know the most about are game development, networking, and web development, and in all of those, it's not the case that only 1% of the code is in the "edge case" where performance matters at all.

For example, in the case of web development, if you build a medium-sized website with React (i.e. pretty normal behavior nowadays), then if you make default decisions that don't consider performance at all, your website will end up noticeably slow, because you will:

1. Write code that re-renders components all the time during loading and UI interactions,

2. Which depend on tons of third-party dependencies that perform poorly,

3. So you end up spending a ton of time in re-renders while the site loads and while someone is using it.

Dealing with this isn't literally the same performance work that Casey put in his article, because it's at a slightly higher level of abstraction, but it requires the same mindset. It requires writing most of your code (and taking on dependencies) with performance in mind, not just 1% of it. You can't avoid it without your notion of "clean code" including some amount of mechanical sympathy, rather than just being about abstract extensibility and generalization concerns.

Re:“Clean” Code, Horrible Performance by whstl on Tuesday February 28, 2023 @07:14PM (#34976890)
It's also very easy to mess up the performance due to architecture when using modern frameworks. For example: as much as SPAs are reviled, if you have a complex enough web application with heavy components, having it being an SPA might be better in terms of perceived speed than having it do a full reload on every navigation.

This is a mistake that I see far too many government and utility sites making.

Re:“Clean” Code, Horrible Performance by Aeolun on Tuesday February 28, 2023 @07:50PM (#34977249)
Except that in React writing clean code will actually make your application faster.
Re:“Clean” Code, Horrible Performance by engineeringwoke on Tuesday February 28, 2023 @08:16PM (#34977469)
Re-renders are incredibly cheap in the big picture. They are not a source of performance bottlenecks in 99% of real world applications
Re:“Clean” Code, Horrible Performance by xtian on Tuesday February 28, 2023 @09:12PM (#34977892)
So why do 99% of real world applications run like garbage? What’s the culprit?
Re:“Clean” Code, Horrible Performance by simplotek on Wednesday March 01, 2023 @02:30AM (#34979708)
> So why do 99% of real world applications run like garbage?

If you're really interested in the impact of performance issues on everyday life, you need to provide concrete examples instead of putting up unverifiable strawmen.

The truth of the matter is that 99% of real world applications run just fine, and it doesn't pay off to invest in shaving milliseconds here or there. Would it be desirable to have a magic wand to improve some edge cases? Yeah, why not? Is it worth to pay people to spend time with a stopwatch at hand to shave off these milliseconds? Not really. It's all about tradeoffs, and there is no real world payoff in wasting developers' time to shave off that millisecond here or there.

Re:“Clean” Code, Horrible Performance by wruza on Wednesday March 01, 2023 @03:30AM (#34980042)
The promise of frameworks like React is that you write code in their way and they take care of performance, because functional, declarative and all that. You just use primitives and don’t control how it all works under the hood. Coping may be a good strategy here, but isn’t a good argument.
Re:“Clean” Code, Horrible Performance by nottorp on Wednesday March 01, 2023 @03:31AM (#34980047)
You basically waste millions of seconds of users' lifetime instead :)

Not to mention that web apps redrawing everything whenever they feel like it can almost give motion sickness, lead to clicks on the wrong things etc.

Yeah, but users' time is worthless.

Re:“Clean” Code, Horrible Performance by mtrower on Wednesday March 01, 2023 @04:00AM (#34980251)
You know, I started on some concrete examples for you, but I had to stop and back up. Really? You can't think of any examples yourself? The modern web is absolute hell to use if you aren't on modern hardware. Try it sometime; use a 10 year old phone, or an old computer that wasn't built top-of-the-line.

There's so much hardware out there that can run native applications just fine, that can play back HD video, that can run complex 3D real time video games, but crawl like molasses when loading your average webpage. Facebook and YouTube are terrible offenders, but so are your average blogs. Many banking websites are terrible (yet they don't have to be; my local credit union has a zippy website that looks attractive to boot, has modern design elements, etc.).

Maybe the hardware you're running is eye-wateringly fast, or maybe it's just barely fast enough and you don't need the cycles for anything else. But we're not talking milliseconds. We're talking order(s) of magnitude. I can't bring myself to believe you don't see at least some of it, if you just open your eyes and look around.

Re:“Clean” Code, Horrible Performance by albedoa on Wednesday March 01, 2023 @08:08AM (#34981951)
> Really? You can't think of any examples yourself?

"Unverifiable!", he wrote from within a web browser.

Re:“Clean” Code, Horrible Performance by whstl on Wednesday March 01, 2023 @04:02AM (#34980263)
Since we're talking about React, Facebook's web app is incredibly slow to me, and typing text in some fields is slower than me. As in, it sometimes takes a second for the letters to start showing. And no, it's not a browser rendering issue (even if it were it would be terrible), as disabling JS in Safari brings back the performance.

Another app that I'm not sure if it's React or not is New Reddit. It is significantly slower on my computer and on a lot of people's computer and sometimes you have to refresh the page because it consumes too much memory.

I can come up with other local examples, from Germany. Vatenfall's website seems to "traditional" page navigation, but the content is loaded via a framework. Due to having to reinitialize everything, text takes up to 5 seconds to appear when using the back button or when navigating for page to page. Similar things happen in the German Agentür fur Arbeit.

Re:“Clean” Code, Horrible Performance by cnity on Wednesday March 01, 2023 @04:22AM (#34980353)
My hot take is that React doesn't directly _cause_ slow performance, but that React is so well marketed as a first place to start for new programmers that the bar for quality is much lower than other industries (like game programming, or even "vanilla JS" which is increasingly seen as an advanced approach).
Re:“Clean” Code, Horrible Performance by sanitycheck on Wednesday March 01, 2023 @05:24AM (#34980765)
The trouble with this attitude, is that it misses the fact that the _range_ of computing power of devices which ordinary people use is probably greater now than it's ever been.

Let's not even get into low end phones in developing countries or bargain basement android tablets, let's stick with something straightforward - an ordinary PC.

I took a quick look online, sorting by cheapest first I found something with an AMD 3015e in. Based on cpubenchmark.net that gets a benchmark of 2691. Taking a look at the big list of CPUs I see that's equivalent to a powerful desktop CPU from 2008, or a decent laptop from 2012. (The Apple M2 in the current Macbook Air gets a score of 15369, just for comparison.)

So, if you're writing PC software or making a fancy web app and you want everyone to have a good experience with it then you should see how it runs on a terrible new laptop, or a 12 year old good laptop, or a 15 year old powerful desktop.

(And yeah we all have SSDs now which is much better than in the old days, and JS is generally single thread, and single threaded CPU performance has not improved so much - but I think my point still stands.)

Re:“Clean” Code, Horrible Performance by xtian on Wednesday March 01, 2023 @12:22PM (#34985111)
> The truth of the matter is that 99% of real world applications run just fine, and it doesn't pay off to invest in shaving milliseconds here or there.

You're taking deep quaffs of the Kool-Aid and so are most of the people commenting on this story. General software responsiveness and reliability (i.e., usefulness) has been in decline for decades. This is an objective fact.

Writing objective reality off as mere "milliseconds", "edge-cases", or only relevant for "toy problems" exemplifies the arrogance and severe incompetence of most programmers. People are seriously trying to talk down to Casey Muratori when in all likelihood they haven't accomplished even 1% as much as him as programmers.

I get it—no one wants to leave fantasy-land as long as the easy money is flowing. But sooner or later the glittering carriage turns back into a pumpkin.

Re:“Clean” Code, Horrible Performance by gitgud on Wednesday March 01, 2023 @01:13PM (#34986058)
Go to a slow website on Chrome. Open dev tools and turn on "enable paint flashing", you'll see a seizure inducing light show of re-rendering...

It's certainly a huge problem for real world applications

Re:“Clean” Code, Horrible Performance by mtrower on Wednesday March 01, 2023 @03:42AM (#34980124)
> the whole world is comprised of the 99% of cases where shaving off that millisecond buys you absolutely nothing

Who was talking about a single millisecond here?

I notice, broadly, two types of people who engage in these arguments.

1> OMG, computers are thousands of times faster than they were a decade ago, why is everything not lightning fast? Why are so many things slower than they were back then? Why is my chat program eating 2GB(!) of RAM?

2> Because we're busy writing six billion features on our Nth iteration of this problem space, we can't be bothered to shave a few millis bro!

And they just talk past each other.

Re:“Clean” Code, Horrible Performance by WatchDog on Tuesday February 28, 2023 @05:06PM (#34975595)
Most of these websites have neither clean code nor hyper optimisation, just bad code all round.