News for hackers. Stuff that matters.
Re:The compiler will optimize that away by jupp0r on Sunday May 02, 2021 @10:04AM (#27015391)
The implicit premise of the article seems to be that all software has to be heavily optimized. This is completely wrong. All the languages mentioned in the article are still around because it doesn’t matter how performant 99% of code is. For the 1%, we can think about cache misses, SIMD and data parallel approaches. In my experience this is totally possible and not too hard, but has the enormous downside of making that code hard to reason about. You are also optimizing for today’s hardware, which means that it might not run that great on new hardware in 20 years. This means that somebody has to go in and rewrite that hard to understand optimized code. It’s really a tradeoff between the cost of that and the benefits from optimization.

Some of the future costs can be mitigated by using a few techniques from the start. One good idea is to keep an vanilla unoptimized version of the part that you are optimizing around as a reference implementation. This will help understanding what the optimized code does and can be used as a stopgap to support new hardware. It can also be a nice baseline to compare optimizations against.

The beauty of compilers is that they do a decent job of optimizing the 99% of code that would otherwise never be optimized, at 0 cost. This is a different sweet spot on the cost benefit curve.

Re:The compiler will optimize that away by esailija on Sunday May 02, 2021 @12:18PM (#27016443)
I disagree. Almost all software I use these days is absurdly slower than it should be and probably a massive drain on collective productivity. I have ssd, fast internet, 64gb ddr4 etc, almost everything I do should be impercetibly instant but instead takes seconds and even minutes.

Yeah of course most of that slowness is not even because of ignorance of the low level stuff but complete disregard of performance aspect of software. If it's even slightly more convenient for a programmer to do something that is very stupid performance wise, they will do it.

Sure developer time costs, but this cannot actually be the reason. Because tooling is also ridiculously slow in exactly same way and wastes countless of hours of that costly developer time.

Re:The compiler will optimize that away by toast0 on Monday May 03, 2021 @12:19AM (#27021559)
> I disagree. Almost all software I use these days is absurdly slower than it should be and probably a massive drain on collective productivity.

This is absolutely true, but the problem is usually a lack of due care about performance at higher levels, rather than low level optimization. Things are usually slow because they do entirely too much of the wrong things, than because nobody optimized the things, or the wrong registers were used or what not.

Re:The compiler will optimize that away by edenhyacinth on Monday May 03, 2021 @08:45AM (#27024328)
The article presents the case that writing code with a specific style - OOP compared to Data Oriented - is responsible for slowing down performance. That code architecture is primarily the cause, regardless of the actual implementation, because some architectures will never work well with the compiler.

I get that like the major parts of picking algorithms that are N over N^2 is always going to be more important, but it doesn't seem like the article is disagreeing with you at all, just another area where people need to consider their decisions.

Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @01:00PM (#27027577)
But only a strict subset of problems are heavily data oriented. For your 3 button GUI app whether you use a tightly packed AoS, even SoA doesn’t matter over a slow linked list of pointers for that 3 element list implementation doesn’t matter.

And OOP is simply not contradictory to DOD.

Re:The compiler will optimize that away by toast0 on Monday May 03, 2021 @03:28PM (#27029605)
(Agreeing) The 3 button GUI app is much more likely to be/feel slow because the UI framework used makes it difficult to get the widgets on the screen quickly than because of data processing.

Maybe it insists on a deep heirarchy of widget inheritence as many do. Maybe the framework wants to load and configure all the possible widgets, even though the application only uses a few. Maybe theres a bunch of images loaded from disk even though they're not used. Maybe it's just the fantastic default compositing system that puts everything a frame behind adding up with everything else.

There certainly are applications where data structures matter, and time spent processing data is significant to user experience, but that's not why the whole computing experience feels slower (although maybe prettier) than 25 years ago, despite capability being so much more for most things (as pointed out in the article, ram is better than years ago, and we certainly have more of it, but ram access takes a lot more cpu cycles now)

Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @05:16PM (#27030762)
I am torn on the issue. On one hand, there is definitely useless technical debt, over-abstraction, no longer useful features slowing down our programs. But at the other hand, we are actually handling every language on Earth properly (or at least we very well should already), instead of just saying that yeah ascii is good enough, somewhat care about accessibility though far from enough, etc.

Also, actual native GUI apps are quite fast imo. Only electron apps are slow, but I really do think that it is mostly due to the web having a wrong abstraction for GUIs, not due to other reasons (of course there are shitty web apps, as well as shitty programs everywhere else)

Re:The compiler will optimize that away by WrtCdEvrydy on Monday May 03, 2021 @01:25AM (#27021897)
> Sure developer time costs, but this cannot actually be the reason.

It totally is because we've abstracted the cost of software engineering unto the hardware.

Back in the 90s, people had to basically beg for memory when writing software while modern development is built on the theory of getting the fastest delivery speed at the cost of performance. We outsource the cost of software unto millions of customer's hardware and it's never coming back because going to market quick makes you money.

Re:The compiler will optimize that away by Olreich on Monday May 03, 2021 @07:00AM (#27023565)
The point stands anyway. Why are all my dev tools super slow? If my time is important, shouldn’t those be fast and heavily optimized? And don’t try to tell me that 4 billion cycles a second across 16 cores operating on in-memory contiguous values isn’t enough to update a watch window more than 1 time per second.
Re:The compiler will optimize that away by rbanffy on Monday May 03, 2021 @10:03AM (#27025202)
If my tools are faster than me, there’s no point in making them even faster. In fact, I’d trade some of that speed for a smaller memory footprint.

In your example of the watch window, updating it at more than 30 fps is probably overkill.

One very common mistake is optimising the wrong thing. My advice is always the same: first run a profiler with a real workload (absent that, eu it over your automated tests), then look at what you need to optimise for speed. All the rest should be optimised for readability.

In the article’s case, if counting warriors is so important, keeping a counter at the AntColony class that’s updated every time you write to an Ant would be the obvious solution.

Re:The compiler will optimize that away by WrtCdEvrydy on Monday May 03, 2021 @09:06AM (#27024540)
> Why are all my dev tools super slow? If my time is important,

Quantify important into how much you spend on your tooling.

Aside from some key bits of development software at the IC / board layout, almost everything a software developer needs is free, open source or cheap. Noone pays $1000 for an IDE anymore.

Re:The compiler will optimize that away by harry8 on Monday May 03, 2021 @10:51AM (#27025768)
> Noone pays $1000 for an IDE anymore.

How many minutes per developer per day before that level of expenditure pays for itself inside 2-3 months?

Who cares? The premise is false, you can't buy it. There is no "fast tools" you pay for. Every decent shop got their devs an SSD at the first available opportunity because it paid for itself really quickly, cost you money _not_ to buy them. The very definition of a false economy was "no the devs aren't getting new shiny sportsmode SSDs for their boxes."

We all use gcc and clang (for relevant languages), for example because everything else you might pay for sucks a lot harder. Whatever the ideology you claim or deny. Intel literally damaged their customers' products to try to make themselves look better than AMD with theirs! They're a non-starter after showing themselves willing to do that but if you must, yes, their compilers still suck exclusively on intel more than gcc. How is microsoft's compilers standards chasing going? In the 21st century yet or /still/ not? (Oh come one, we're mostly there but for ... yeah). Compiling template heavy C++? Does developer time matter?

(But just quietly, terminals & cmdline tools feel a lot more productive than IDEs to me and I use both in differing circumstances).

Re:The compiler will optimize that away by vbezhenar on Monday May 03, 2021 @11:18AM (#27026194)
I don't have a hard math here. But here's some example: JRebel. It allows for instant class reloading in JVM. It increases one's productivity tremendously. And it's expensive as hell. They used to have free version, they don't have it anymore. I can only judge that they're struggling and forced to squeeze all they can, because developers will prefer free restricted version over paid full-featured version. I know, I do, I don't value my own time and I'll never pay more than $100/year for a tool (and hopefully much less), I already trying hard to justify Idea subscription, because it seems that Idea CE contains almost everything I need.

If developers would love to spend thousands of bucks here and there, paid developer tools industry would flourish. But I think that it's even degraded compared to the past. I remember paid Delphi IDE and I remember paid components and that was a thing back then. I can't remember any popular paid React component right now, despite the fact that much more people are using React compared to Delphi.

Re:The compiler will optimize that away by 29athrowaway on Sunday May 02, 2021 @08:13PM (#27020308)
Shit is slower than it was in the 90s.

Spotify is slower than Winamp, Slack is slower than IRC, Webmail is slower than my e-mail client, VS Code is slower than Visual C++ 6.0.

Re:The compiler will optimize that away by corysama on Sunday May 02, 2021 @08:30PM (#27020390)
People forget that Winamp was instant on a 60Mhz machine with a spinning rust drive. It’s difficult to buy a computer that slow these days. Modern CPUs modulate their speeds by far more than that as part of their moment by moment power management!
Re:The compiler will optimize that away by fiddlerwoaroof on Sunday May 02, 2021 @08:44PM (#27020457)
Related: when MacBooks switched to SSDs, the performance of my old spinning-disk MBP dropped noticeably basically overnight.
Re:The compiler will optimize that away by Narishma on Sunday May 02, 2021 @09:22PM (#27020687)
Same thing on Windows. It became incredibly slow on HDDs when SSDs started to become popular.
Re:The compiler will optimize that away by selfhoster11 on Monday May 03, 2021 @08:45AM (#27024327)
When I first bought an SSD and noticed the crazy speed-up, my next thought was that developers will get used to it as the "new normal" and stop caring about IOPS which would slow down SSDs (ruining my blink-of-an-eye super-speed fun) and make HDDs near-unusable. Two to four years later, here we were on Windows, and to some extent, on Linux too.
Re:The compiler will optimize that away by jdsully on Monday May 03, 2021 @10:35AM (#27025593)
The amount of effort involved in making sure reads were sequential back in the HDD days was immense. It’s not surprising people dropped that as soon as possible.
Re:The compiler will optimize that away by cassepipe on Monday May 03, 2021 @07:46AM (#27023874)
Having an Hdd running at 100% on Windows 8, slowing everything down, is actually what made me switch to Linux Mint. Never looked back.
Re:The compiler will optimize that away by jayd16 on Monday May 03, 2021 @02:29AM (#27022241)
Winamp didn't stream all music in existence over the internet. How is it really comparable?
Re:The compiler will optimize that away by TeMPOraL on Monday May 03, 2021 @05:51AM (#27023209)
Because streaming music is a trivial task, computationally-wise. It could have had some performance impact in 2000, but we're in 2021 now.

And nothing else related to the functional differences between Spotify and WinAMP can explain why Spotify is slow. Done properly, it should feel snappier than WinAMP felt in 2000.

Re:The compiler will optimize that away by kleiba on Monday May 03, 2021 @04:47AM (#27022871)
It's comparable only on an abstract level - mostly because there's hardly anybody who really wants/needs "all music in existence over the internet", most people just want to "listen to music that I like".

On that level, Winamp did the job just fine.

Re:The compiler will optimize that away by 8fGTBjZxBcHq on Monday May 03, 2021 @08:54AM (#27024412)
It really did not for me by that standard. I have access to orders of magnitude more music now that I know I like than I did during the Winamp days and I was a pretty early and savvy user back then so I had more access than a lot of people.

If we're trading music player performance for the massive increase in availability I'll make that trade.

Re:The compiler will optimize that away by jayd16 on Monday May 03, 2021 @01:03PM (#27027640)
Is that why everyone uses a streaming service and no one collects music any more?
Re:The compiler will optimize that away by tonyarkles on Monday May 03, 2021 @09:27AM (#27024800)
Lol arguably Winamp + Napster did :D

But really, 99% of the value-add of Spotify over Winamp is stuff that happens server-side. Your Spotify client doesn’t have a database of all the songs, nor the ML models for computing recommendations. As far as playing streaming music goes, Winamp would happily play an m3u (mmmm soma.fm).

Don’t get me wrong, the discovery and search features in Spotify have brought me a ton of value. But wow is the client resource usage dramatically disproportionate for the added functionality

Re:The compiler will optimize that away by TeMPOraL on Monday May 03, 2021 @04:31PM (#27030252)
And the kicker is, the music client is a completely separate concern from a song database, or a recommendation engine.

This is actually a point in favor of directly comparing WinAMP and Spotify - the important "value-add" bits of Spotify all happen server side, so they should have exactly zero impact on client performance.

Re:The compiler will optimize that away by Firehawke on Monday May 03, 2021 @02:43AM (#27022307)
It had Shoutcast.
Re:The compiler will optimize that away by jayd16 on Monday May 03, 2021 @03:04AM (#27022397)
Was Shoutcast all that fast? It didn't seem nearly as rock solid as the rest of winamp but I guess it could have been my internet at the time.
Re:The compiler will optimize that away by 29athrowaway on Monday May 03, 2021 @11:52AM (#27026646)
You could go to the shoutcast website, get the shoutcast links for the radios you were interested in, then make a playlist that could be dealt with just like any other playlist.

And it was almost instant.

Re:The compiler will optimize that away by goodpoint on Monday May 03, 2021 @07:34AM (#27023788)
Yes, it was instant.
Re:The compiler will optimize that away by 29athrowaway on Sunday May 02, 2021 @09:34PM (#27020759)
Winamp 2 was instant. Winamp 3 and 5 were slow.
Re:The compiler will optimize that away by krapp on Monday May 03, 2021 @05:38AM (#27023142)
>Spotify is slower than Winamp, Slack is slower than IRC, Webmail is slower than my e-mail client, VS Code is slower than Visual C++ 6.0.

All of which are Electron apps, apart from "Webmail" which is, well, what one might call a "distributed Electron app" (a website.)

Maybe, just maybe, Electron is the problem.

Re:The compiler will optimize that away by jupp0r on Monday May 03, 2021 @06:57PM (#27031983)
Spotify is not an Electron app, they are using Chromium Embedded Framework.
Re:The compiler will optimize that away by fiddlerwoaroof on Sunday May 02, 2021 @08:44PM (#27020452)
Yeah, this is the weirdest thing to me: Windows NT 3.51 on a Pentium was much snappier perceptibly than even my new M1 MBP (developers are already expanding to the new performance envelope).
Re:The compiler will optimize that away by haberman on Sunday May 02, 2021 @09:02PM (#27020564)
Dan Luu has done some measurements around this:

https://danluu.com/input-lag/

https://danluu.com/term-latency/

Re:The compiler will optimize that away by 29athrowaway on Sunday May 02, 2021 @11:38PM (#27021366)
Similarly, SNES games were more responsive than modern games and have zero loading screens.
Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @01:15PM (#27027812)
And didn’t render millions of polygons at 60+ fps, while having many GBs of assets like textures, so I don’t see how is it relevant.

One could write those programs in a truly inefficient manner in a not too performant language and it would run without problem. Today’s computers are really fast.

Re:The compiler will optimize that away by fiddlerwoaroof on Monday May 03, 2021 @01:20PM (#27027894)
The problem is that, instead of the speed of modern computers translating to perceptible performance improvements for normal users, it translates to applications that use more resources.

Whether or not the new features make up for the general perceptual slowness of modern computers is a somewhat open question.

Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @04:17PM (#27030118)
I would agree with you, but in terms of games it is simply not a great example. It may be questionable why would we want photorealistic games when 2D, visible pixels are good enough, but games are not known for being inefficient.
Re:The compiler will optimize that away by 29athrowaway on Monday May 03, 2021 @09:28PM (#27033092)
Yet many of the games were more entertaining than many games today.
Re:The compiler will optimize that away by kaba0 on Tuesday May 04, 2021 @03:09AM (#27034776)
That’s completely orthogonal.
Re:The compiler will optimize that away by XorNot on Sunday May 02, 2021 @10:19PM (#27020974)
Windows Server 2019 has a much snappier UI then Windows 10 I've found (I recently spent a ton of time automating installs for both and boy did that become noticeable).

Then you look at the Windows 10 list of crapware and it becomes a lot clearer.

Re:The compiler will optimize that away by Spooky23 on Sunday May 02, 2021 @11:47PM (#27021424)
Windows 10 is an abomination.

It’s incredible how much grief Windows Vista got in comparison.

Re:The compiler will optimize that away by selfhoster11 on Monday May 03, 2021 @08:50AM (#27024362)
Vista was a worse abomination on 2 GB of RAM. It's likely that if I installed a build of Windows 10 from 2 years ago on the machine in question, it would be faster than a greased lightning in comparison.
Re:The compiler will optimize that away by stinos on Monday May 03, 2021 @03:16AM (#27022461)
Then you look at the Windows 10 list of crapware and it becomes a lot clearer.

Is there an actual causal relationship? And which crapware specifically? Asking because I only have access to a bunch of Windows 10 Pro machines which already don't seem to have most of crapware on there (i.e. often I see threads here where people complain about all kinds of ads and other things I never even knew existed) and the rest disabled (as far as I can tell) and still it's less snapy than this one Windows Server instance on comparable machine. (and sadly no single modern OS feels as snappy as even Windows XP SP2 for a similar level of functionality on not-so-recent hardware)

Re:The compiler will optimize that away by freeone3000 on Monday May 03, 2021 @07:32AM (#27023775)
The difference is the list of running background services. Kernel and drivers are the same, libraries are the same, but server doesn't have (ex) the AllJoyn Router Service for Smart Things Control, the 4G LTE Push Notifications Service, the WAP Push Message Service, the Fax Service, Windows Image Acquisition, and so on. Candy Crush doesn't run on startup, these do.
Re:The compiler will optimize that away by User23 on Monday May 03, 2021 @10:36AM (#27025606)
The subjectively fastest, which is to say the most responsive or lowest input latency, computer I've ever used was a Macintosh 512ke upgraded to 2.5 megabytes of memory, running the system software and apps off of a 1.5 megabyte RAM-disk. When you double-clicked, say, MacPaint in the Finder, it was loaded before you finished the physical mouseup. This was when that hardware and software was still current.
Re:The compiler will optimize that away by reynhaim on Monday May 03, 2021 @09:41AM (#27024951)
Spotify runs on all of my devices. In the morning I can ask my smart speaker to play songs that Spotify presumes I like, continue from my car with a voice command, see what my friends are playing or play their playlists. I'll gladly wait for the ~5 seconds it takes for an app to start if it delivers all this.

Of course IRC is much faster, it's also few orders of magnitude simpler than Slack. For work related communications I prefer Slack to IRC, but for chatting with friends IRC does just fine. One simple protocol vs hundreds of APIs that provide extremely rich content. Once again, Slack takes few seconds to launch on a modern machine, it's not that bad considering it does so much.

Yeah shit is slower, shit is also way more connected and complex than in the 90s.

Re:The compiler will optimize that away by astrange on Sunday May 02, 2021 @11:54PM (#27021462)
Slack is definitely faster than my IRC client since it's not running over ssh to a host. You can't actually run IRC locally or you'll miss all the chat from when you're not signed in.
Re:The compiler will optimize that away by Shikadi on Monday May 03, 2021 @12:47AM (#27021689)
You can use a bouncer so that's not true
Re:The compiler will optimize that away by quadcore on Sunday May 02, 2021 @09:16PM (#27020653)
I dont know if you've noticed, but most programmers actually do care about performances. They just are bad at it. Software are slow precisely because programmers dont get it: optimising all the code will make slow software. They spend their budget optimising 99% of the code and end up with no more money to make that last 1% fast. For real (game engine programmer speaking). Plus optimising all the code make all the code unreadable which drains even more money from budget. Just as OP said.
Re:The compiler will optimize that away by astrange on Sunday May 02, 2021 @11:53PM (#27021455)
Usually simpler code is better. I used to see a lot of mistaken "high performance" code where someone has unrolled all of the loops because they think unreadable code goes faster, though maybe people have gotten better about this? (OpenSSL is an example here.)

Unfortunately not all kinds of slowness only happen in hotspots. This is true for CPU cycles, but if an occasional task uses all memory, it's going to mess up everything downstream as well.

Re:The compiler will optimize that away by Sohcahtoa82 on Wednesday May 05, 2021 @06:31PM (#27056644)
I wonder where the trade-off is for loop unrolling.

Like, unrolling a `for` loop that only has 5 iterations makes sense. But if you have 100 iterations, then the larger memory footprint of all the code might actually make it slower than just keeping the `for` loop.

In some cases, you can use Duff's Device. https://en.wikipedia.org/wiki/Duff%27s_device

Re:The compiler will optimize that away by selfhoster11 on Monday May 03, 2021 @08:42AM (#27024302)
> I dont know if you've noticed, but most programmers actually do care about performances. They just are bad at it.

I disagree. Programmers may care about performance, but project managers certainly don't and they always have the final say.

Re:The compiler will optimize that away by goatinaboat on Monday May 03, 2021 @10:19AM (#27025394)
Programmers may care about performance, but project managers certainly don't and they always have the final say

LOL no. Offer a dev choice between a framework that is trending on Twitter, vs one that is 100x faster but "legacy" (meaning more than a year old) and she'll choose the first one every time, and the project manager won't know the difference, or care if he did.

Re:The compiler will optimize that away by selfhoster11 on Tuesday May 04, 2021 @04:03AM (#27035062)
If it's good to develop with, I don't care one whit whether a software framework is 2 months old or 20 years old. Besides, not everyone works on greenfield projects and can pick what framework they want.
Re:The compiler will optimize that away by tonyarkles on Monday May 03, 2021 @09:22AM (#27024706)
I’m with both of you and I don’t think what you two are saying is mutually exclusive. I’m kind of a performance nut (often working with teams, I’m the guy that introduces everyone to a profiler) and, in my N=small experience, PMs are opposed to spending time on performance optimization precisely because most people are bad at it and it takes an undefined amount of time for unknown performance gains.

When I take an hour to profile and analyze some request and say “I think we can cut this thing’s response time by 80% by optimizing $X, which will result in an overall page load time reduction of 3s”, that’s way easier to sell than “I want to figure out why this page load is so slow” and then reporting back a week later with “shrug I optimized 5 things and it didn’t get faster. Dunno.”

Re:The compiler will optimize that away by 8note on Monday May 03, 2021 @12:15AM (#27021546)
Most performance concerns that I run into are related to advertisements that need to load.

The business model isn't right for performant experiences

Re:The compiler will optimize that away by GuB-42 on Monday May 03, 2021 @04:33PM (#27030273)
Faster = more ad revenue. If your app/site is too slow, people will stop using it and won't see your ads. Also, search engines will detect that and downrank you, meaning even less ad impressions. It has been studied many times, and yet, developers don't do it.

Simply, performance is expensive and for most businesses, the additional revenue is not worth the additional expense.

Re:The compiler will optimize that away by goatinaboat on Monday May 03, 2021 @06:58AM (#27023556)
Almost all software I use these days is absurdly slower than it should be and probably a massive drain on collective productivity

Productivity, energy usage, e-waste in landfill as people are forced to upgrade in order to do simple tasks with the current software... The world is paying a high price for programmer laziness.

Re:The compiler will optimize that away by city41 on Monday May 03, 2021 @09:36AM (#27024902)
Is it programmer laziness, or insane demand for software due to many factors, mostly profit?
Re:The compiler will optimize that away by goatinaboat on Monday May 03, 2021 @10:15AM (#27025344)
Is it programmer laziness, or insane demand for software due to many factors, mostly profit?

There's insane demand for games, and those programmers are able to optimise their code, insane demand for trading software and those programmers are able to optimise their code. But webdevs just don't care. I look at pages now that do nothing more in functionality than the same app would have done 20 years ago, yet they are slower now, and I have literally 1000x more CPU power. It's insane.

Re:The compiler will optimize that away by city41 on Monday May 03, 2021 @10:27AM (#27025478)
Optimized games have a well known impact on sales. I'd assume the same with trading software. Putting out a blanket statement that web devs are lazy is just silly. Developers rarely have much say in how much time they can dedicate to features and the app as a whole, that usually boils down to PMs and management. If the org as a whole doesn't value performance or doesn't think it matters, then that will get reflected in the product regardless of what the developers actually want.
Re:The compiler will optimize that away by jupp0r on Sunday May 02, 2021 @07:06PM (#27019908)
Do you use browsers? Browser makers spend billions of dollars in engineering time making them "fast", with great results.
Re:The compiler will optimize that away by klyrs on Sunday May 02, 2021 @07:57PM (#27020212)
Do you use websites? Because developers unthinkingly pull in billions of dependencies, making them "features", with horrific results.

And fast is one aspect of performance. What's the memory footprint?

Re:The compiler will optimize that away by Silhouette on Sunday May 02, 2021 @09:28PM (#27020725)
And yet developers working on front-end code to run in those browsers are waiting seconds for their linter or test suite or transpiler to process a few thousand lines of JS code, on a modern PC. Not a few million lines, a few thousand. That is orders of magnitude slower than it should be, and it's a cost that hits huge numbers of developers many times every day. Quite often, that awful performance is because the slow tools are written in a certain language also used in those "fast" browsers, and far too many developers are still giving this a pass because they incorrectly assume some magical runtime and JIT will make up for using a language that was never designed for high performance work and writing large, complicated programs.
Re:The compiler will optimize that away by pwdisswordfish8 on Monday May 03, 2021 @09:26AM (#27024763)
The problem with the NPM ecosystem is really dire because know-nothing programmers who write JS plug in to that ecosystem and write bad code, and then the know-nothing programmers who don't write JS come along, too, and say look how bad JS is.

JS is plenty fast and can be used for "large, complicated programs"[1] just fine. The problem with most JS written today is in programmer practices—the way that the community associated with NodeJS pushes one other to write code (which is, ironically, not even a good fit for the JavaScript language). It turns out that how you write code actually matters (which is the central point of the article here to begin with...)

1. https://web.archive.org/web/20070127104743/http://www.spread...

Re:The compiler will optimize that away by sudosysgen on Sunday May 02, 2021 @07:15PM (#27019947)
Browsers are fast, but the content they render is very slow.
Re:The compiler will optimize that away by fiddlerwoaroof on Sunday May 02, 2021 @08:42PM (#27020439)
These are related: the faster the browser and the typical internet connection is, the bigger sites will be (absent some force to prevent developers from spending the entirety of the new performance budget.)
Re:The compiler will optimize that away by bogdanoff_2 on Sunday May 02, 2021 @09:05PM (#27020587)
Reminds me of the "paradox" that making technology more energy-efficient has the effect of increasing overall energy use.
Re:The compiler will optimize that away by CalChris on Sunday May 02, 2021 @09:57PM (#27020884)
Re:The compiler will optimize that away by toss1 on Monday May 03, 2021 @08:01AM (#27023973)
>"Browsers... "fast", with great results."

Are you joking?

I have seen progressively worse performance from even the best browsers, and page load times that should be instant often literally take minutes or never load unless I completely kill the browser process and return. The slowdown is nearly inexorable, with occasional improvements in some versions before resuming the dismal trend.

Simple word processing and spreadsheets are so laggy on keystrokes as to be almost unusable, and by unusable, unresponsive on a level hundreds of times worse than DECADES ago, on computers orders of magnitude less powerful. Simple cursor movements are so laggy that I must set aside my train of thought to attend to the tool.

And this is on a very solid CAD-level computer, FIOS connection, etc.

It is disgusting and unforgivable. I quit software career 15 years ago for a new industry in no small part because I saw this trend of ever more complex "tools" & "frameworks", etc. creating a situation of building castles on shifting sands, with serious declines in the ability to reason about debugging, performance, or security. It is only worse now, probably exponentially. Worse yet, it seems to have yielded no perceptable "programmer productivity".

It is one thing to architect and program to take advantage of upcoming advances in hardware. It is quite another thing to ignore it and assume that the hardware builders will save you from the bloatware that you foist on the world without a serious thought.

Re:The compiler will optimize that away by pwdisswordfish8 on Monday May 03, 2021 @09:11AM (#27024597)
> Are you joking? I have seen progressively worse performance from even the best browsers

Where is the evidence that you're seeing poor performance from the browser itself and that the source of the problem does not lie in the difference between what the server is sending down the tubes today compared to what it was sending 10 years ago?

Re:The compiler will optimize that away by toss1 on Monday May 03, 2021 @12:42PM (#27027284)
I agree that what the server is 'sending down the tubes' is a huge part of the problem.

But this is the root cause we're discussing - programmers selecting tools for their convenience (and worse yet, cool factor), instead of FIRST considering the responsiveness of the system as they design and code.

Optimization as an afterthought is about as good as security as an afterthought - anything from a complete waste of time to a disaster.

There are indeed pages that load like lightning, so it can be done (e.g., HN takes about 1.5sec to create a new window and load, so not exactly lightning, but usable), but many are horrible, and clearly due to bad programming.

For starters, when I see a page that loads code from 25 different sites that need NoScript privs to even display, that alone is pretty questionable - license and manage your own damn code (for the sake of minimizing dependency alone!). Twitter is particularly egregious in the last year or so, a new page taking 10sec-?? to load, and the LAST thing that loads is the list of posts -- the same load times it would feel so much more responsive if that was the first to load, and the other navigation, news, etc. panels loaded later while I was reading. That is a many bad programming choices.

Re:The compiler will optimize that away by pwdisswordfish8 on Tuesday May 04, 2021 @11:23AM (#27038556)
> this is the root cause we're discussing

It's not. Someone explained that browser makers spend billions on top talent to make browsers fast, and you posted a flippant comment — "are you joking?" — about your observations that performance of browsers is getting worse.

Now you're talking about stuff that web developers do on the pages that you visit.

Browsers are an example of software that is fast because companies have put effort into making them that way, instead of not caring. That's the claim made by the person you responded to. Dispute it, if you want, but don't make claims and then change the subject or shut down inquiry into the things that you're saying.

Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @01:09PM (#27027711)
But the browser itself is plenty fast. Just open a huge static HTML file, or some well-optimized JS one like some simulation.

The problem is some websites

Re:The compiler will optimize that away by vbezhenar on Monday May 03, 2021 @11:32AM (#27026372)
I'm using very underpowered laptop (Dell 3410) and web is extremely fast for me. There's some serious problem in your OS or your network if websites take minutes to load. Dreadful gmail or youtube loads in 1-2 seconds for me and then works instantly. Simpler websites like HN loads in a fraction of second.
Re:The compiler will optimize that away by jupp0r on Monday May 03, 2021 @06:52PM (#27031934)
Maybe you should visit better websites? Try http://www.quakejs.com/
Re:The compiler will optimize that away by kleiba on Monday May 03, 2021 @04:49AM (#27022881)
Re:The compiler will optimize that away by einpoklum on Sunday May 02, 2021 @03:42PM (#27018323)
You're both right - but about different kinds of software.

I believe the GP post was thinking an application which has some heavy computational kernel to it, where most of the processor time (and other resources) are spent - with a lot of other code for UI, configuration, some parsing etc.

And you seem to be talking about everyday desktop applications: Browser, mail client, word processor, instant messaging client, and maybe even your IDE as a programmer. Those kind of apps don't have that kernel of hard computational work - their work is much more diffuse.

Re:The compiler will optimize that away by jupp0r on Sunday May 02, 2021 @07:05PM (#27019897)
I spent years optimizing physics simulations from different domains (weather, fluid dynamics, all sorts of stuff). Even there you have to carefully pick the parts you want to optimize to get the best outcome for the resources you invest in optimization. It's completely infeasible to make everything crazy fast with a blanket approach.
Re:The compiler will optimize that away by klyrs on Sunday May 02, 2021 @08:38PM (#27020424)
You're speaking directly past your parent's point. I've spent years optimizing physics simulations, more abstract discrete math stuff, etc. myself. There, especially there, it's usually pretty easy to identify what should be the hot loop, by eye. Easier with a profiler if the project gets big. In scientific computing, it's very common to find that 99% of the time is spent on a scant few lines of code. Unless somebody bungs up the I/O and you end up spending 99% of the time there instead, but I digress.

But a whole OS, with a browser, network stack, dozens of applcations, etc., it's pretty common to find hundreds or thousands of things which are all more or less equally sucking performance. So on one hand, it's a much harder problem. On the other hand, front-end people have this attitude that performance doesn't matter because hardware is fast enough and it's better to write in the most abstract language possible because changing diapers makes your hands smell gross.

Re:The compiler will optimize that away by jayd16 on Monday May 03, 2021 @02:31AM (#27022250)
I think you missed the point. Parent is saying that without compiler optimization everything would be even slower.
Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @12:54PM (#27027488)
I disagree that everything would be slow. Yeah, there are websites with so many JS bloat that they can make the fans start up in my laptop, but otherwise, your computer does a shitton of things, most of which is essential complexity.

To-the-point software is actually really fast, like gcc/clang does tons of optimizations compared to what compilers did a few decades ago, and I doubt you could realistically optimize it by a significant percentage in the general case. Same for databases. Browsers themselves are also pushing the boundaries of hardware, they can display static HTML/CSS ridiculously fast even though it is not ideal for layouting. Pretty much only the top of the abstractions “suck” sometimes, but there are really fast JS apps as well.

Re:The compiler will optimize that away by noobermin on Monday May 03, 2021 @08:41AM (#27024290)
This attitude is very common and has clearly degraded software development particularly for users, and like most issues afflicting modern software it's not perceived by developers so it "doesn't exist" to them. As the top reply to this mentioned, anyone can easily tell how much slower software is today even when computers and devices are so fast now! All in the name of "making code easy to reason about."

I have news for you, all code is difficult to reason about at some level. Sure, certain abstracts can be easier to reason about than others if you take certain examples that I can generally argue are reductionist, but any reasonably well developed piece of code (read, actual useful code) will require a certain level of sophistication and complexity that will eventually make it difficult to reason about.

I know this is a reach and a bit of a red-herring, but developers really really need to remember the allergy to "code being difficult to reason about" is a sometimes a useful intuition or heuristic to use, the heuristic being "easier to reason about is better," but it really is a heuristic at the end of the day. Abuse of this heuristic is often a motive behind all sorts of detrimental behaviors in tech, reinventing the wheel and NIH (I didn't write, it, so it's difficult to reason about!), rewrites from scratch (our "technical debt" is now hard to reason about, let's rewrite from scratch!) and the problem OP refers to (a solution that maps to the machine better is hard to reason about, let's use this less efficient solution instead!). And a big problem here is that these issues are often not issues to hackers because it just means more programming for them which they love! It just hurts users and customers.

Re:The compiler will optimize that away by reader_mode on Monday May 03, 2021 @09:40AM (#27024940)
>As the top reply to this mentioned, anyone can easily tell how much slower software is today even when computers and devices are so fast now! All in the name of "making code easy to reason about."

Yeah - it also doesn't crash my PC when an app segfaults, hell even video driver failing these days won't bring my system down. I don't need to restart my PC when I plug in a device. That's not really compatible with your childhood DOS games that enter kernel mode and talk to HW directly - you pay for abstractions - and it's a good tradeoff.

I can also have files with more than 5 character file names, and my FS can revert file changes and create snapshots.

These "good old days" people are just unrealistic, VIM is fast even today - but I prefer having a graphical representation of file tree with fancy icons and search. But that's just me and 99% of people out there.

Performance is a feature - and it's not a feature most people rank high untill it becomes an issue. As much as a minority of people here are crying about electron and HTML - a huge number of developers use VSCode daily and enjoy the approachability of a JS/DOM plugin ecosystem. VIM is free and available for decades now, and it has such amazing UX that the one of the most upvoted questions on SO was how to exit from it...

Slack is dog slow - and IRC has been freely available for decades, most people here use Slack daily. Who uses IRC anymore ?

So keep using your Emacs integrated window manager and stop bothering the rest of us :D

Re:The compiler will optimize that away by noobermin on Monday May 03, 2021 @11:27AM (#27026322)
My point really isn't about luddite vs. anti-luddite, I'm talking about performance and how it affects users. Also, you're right that less performant or less elegant tools win out sometimes (like the good old mac vs windows debates before macos and apple in general made a come back) and that is due to a variety of reasons. That's fine, life is complicated and many factors affect who wins in life, it doesn't mean we can't still ask for better things though.

Still I don't know what bearing of all this has on the point I made above.

Re:The compiler will optimize that away by 8fGTBjZxBcHq on Monday May 03, 2021 @08:59AM (#27024471)
I think other users in here are more on the right track about where the blame for this lies.

As you alluded to, a lot of programmers are happy to tweak and refine for ages so it's probably not that.

Is it just that programmers are lazy or need to care more or be better educated about optimization?

Honestly I really doubt it. I fully agree with the other takes that companies have incentives to ship working software quickly. Features sell subscriptions not performance. If it comes down to choosing between functionality and performance leaders will ship the slow feature every time.

I'm not even sure they're necessarily wrong most of the time. If you know where to look the internet is a graveyard of carefully engineered products that were beat to market and obliterated by three people with a shitty electron app.

Re:The compiler will optimize that away by noobermin on Monday May 03, 2021 @11:12AM (#27026107)
You're probably right honestly that bean counters are mostly to blame. I will say the attitude of being afraid of difficult code is a problem in modern IT (IT of any generation really) and doesn't help but companies not caring about users being the primary cause of bad, unperformat code is the correct take. Conversely then, the handwaving of the OP comment is wrong too, so if we limit the discussion of what one ought to do, I still stand by my point.
Re:The compiler will optimize that away by lumost on Monday May 03, 2021 @11:39AM (#27026461)
I generally only observe value in application code optimizing for correct data structures/batching/data parallelism. Once you're getting into fine tuning the batch size/SimD ops for a particular platform you are quickly into the realm of diminished ROI due to fragility against changing hardware, application usage patterns, and diminished returns where dropping an op from 1 microsecond to 10 nanoseconds just doesn't matter as much.

There are cases at the tail where this will make or break a project, but those are pretty rare.

Re:The compiler will optimize that away by bobcostas55 on Monday May 03, 2021 @11:00AM (#27025907)
This is exactly how we ended up with someone charging you $50/month to run a browser on a supercomputer.
Re:The compiler will optimize that away by dahart on Monday May 03, 2021 @11:07AM (#27026031)
> All the languages mentioned in the article are still around because it doesn’t matter how performant 99% of code is.

It’s worth challenging this assumption and asking whether it’s really true, or whether this belief is old and outdated like the old languages. I’m certain that providers of compute infrastructure like Amazon, Microsoft, Google and others completely disagree that performance doesn’t matter. Letting slow code run literally costs them money because it prevents multiple people from being able to use the same hardware resource. Even on your own machine, slow processes hog resources that other processes could use. The reason my laptop fans keep spinning up in Windows while my machine is basically idle is due to hundreds of processes written by people who erroneously believe the performance of 99% of the code doesn’t matter. We’re also at a point where we’ve started to measure the energy efficiency and environmental impact of wasting compute cycles. So, performance always matters.

> For the 1%, we can think about cache misses [...] but that has the enormous downside of making code hard to reason about.

You’re agreeing with the author here. Maybe you missed the explicit point in the in the article that is calling for a language that makes basic cache awareness a first class citizen, precisely so that it’s easier to reason about?

“This is exactly the type of problem that should be solved via the features of our programming languages, since writing these custom sorting functions is very tedious. What if a programming language would provide us with a structure that would act like an array of structs, but internally it would really behave like a struct of arrays? We could program in the typical object oriented way that is convenient for humans, while still enjoying in great performance due to playing nice with the hardware.”

> You are also optimizing for today’s hardware, which means that it might not run that great on new hardware in 20 years.

For the last 20 years, the need to be cache-aware has increased in importance. For the next 20 years, the gap between memory and compute will get larger still. There’s no scenario on the horizon where we don’t have to become more memory conscious as programmers or use more memory conscious languages and tools. There aren’t many performance tricks and concepts that worked 20 years ago and don’t work today. Using a structure of arrays (SoA) instead of an array of structures (AoS) has long been and will continue to be a good idea.

Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @01:21PM (#27027908)
Feel free to profile a high-profile application. It is almost always a few hotspots that “suck”.

There are rare cases where there is no one point that is slow, that’s a bad situation to find oneself in — it usually means that the base architecture/abstraction sucks and needs a big refactor.

But even in so low-level code as the linux kernel, you see the use of linked lists all the time. Because it simply doesn’t matter if you are not in a hot loop and iterate slowly over 3 elements.

Re:The compiler will optimize that away by dahart on Monday May 03, 2021 @02:05PM (#27028553)
FWIW, I profile intensive applications all the time, it's my job. You're right about the existence of hot spots, but that's not particularly relevant to my point or the author's. Just because one spot is hot doesn't mean you should rationalize using lazy or bad-practices programming on the rest. Just because you don't see a bottleneck somewhere when you profile doesn't mean it'll stay that way when other processes want the same resources at the same time. Knuth's famous quote was not intended to be a license to ignore using best practices in general for non-hot-spot code.

Use of linked lists in the linux kernel is also not very relevant, and somewhat of a red herring. Kernel-level (as well as games & embedded programming) linked lists are frequently allocated and used very differently from typical high level language linked lists. Scripting languages are allocating individual linked list nodes by default. Linux uses linked lists for the memory allocator itself, for example, and allocates nodes at a lower level in blocks. There are no particularly good alternatives, and no great ways for the allocator itself to be cache aware, though that is ongoing research. The main perf problem with using linked lists in high level languages is not the fact that they cause cache-incoherent access, it's worse, it's the fact that they allocate and deallocate memory constantly which is much much slower. This is one reason why linked lists don't get used as much as arrays in high level languages, when arrays are a reasonable alternative.

Anyway, it's somewhat of a straw man to bring up linked lists when the author's valid point was SoAs are better than AoSs from a cache perspective, and that our languages aren't yet doing much to help us code that way, but they could in the future if we decide to want them to.

Re:The compiler will optimize that away by kaba0 on Monday May 03, 2021 @04:40PM (#27030351)
I apologize for my cocky reply.

I just meant to point out that SoA vs AoS or an even slower data structure is not necessarily relevant for all programs.

> The main perf problem with using linked lists in high level languages is not the fact that they cause cache-incoherent access, it's worse, it's the fact that they allocate and deallocate memory constantly which is much much slower.

This is not true though; at least the JVM most definitely doesn’t do that, and I’m sure other state-of-the-art GCs neither, like V8.

First of all, allocation is basically free, much faster than malloc and friends. It’s only a pointer bump. And the cost of deallocation is amortized/may not even happen. With plenty of memory available, GC doesn’t really happen, and for long-lived objects in case of a generational GC, they may not necessarily get checked at all after a time.

So the usual linked list gets appended a few times is close to optimal, iteration has the same cost as in lower level languages with pointer chasing (usually a bit more because objects usually have headers that take quite some space, less of them potentially fitting into cache). It even has some advantage in that a modern compacting GC may move the objects close to each other.

Re:The compiler will optimize that away by godshatter on Tuesday May 04, 2021 @11:30AM (#27038655)
>So the usual linked list gets appended a few times is close to optimal, iteration has the same cost as in lower level languages with pointer chasing (usually a bit more because objects usually have headers that take quite some space, less of them potentially fitting into cache). It even has some advantage in that a modern compacting GC may move the objects close to each other.

I wonder why array-backed linked lists aren't more of a thing. I've used those before in C in hobby projects. You allocate an extendable array of nodes and the nodes next and/or prev pointers become indices in the array (although pointers would still work). Added nodes go on the end, deleted nodes stay where they are and just aren't referenced. If there is high churn, do something to keep track of inactive nodes to fill next. You're still spamming around an area of memory when iterating the list, but it's at least confined to one guaranteed contiguous block and you're only allocating to extend the array and not doing a lot of allocating and freeing of memory. You still have the memory overhead of the next/previous indices, though, so fewer nodes fit in cache than otherwise would.

Re:The compiler will optimize that away by dahart on Tuesday May 04, 2021 @02:01PM (#27040511)
Agreed, especially for high level languages and application level linked list usage. Worth mentioning I think the good linked list libs usually do this under the hood, and kernel & allocator level linked lists are always doing this. People implementing simple linked lists themselves, and/or copy-pasting the kind of code you get by searching for simple code examples (like the link in my sibling comment here), that's when they end up with very poor performing linked lists.

A closely related concept to what you're describing is internal storage linked lists [1], meaning the class/node contains the link(s) and is specialized for one particular kind of data, which often makes it more compact, and easier to allocate a block of nodes in a single call.

Anyway, I'd guess a big reason it's harder to find array backed lists when searching for linked list implementations is just because it's more advanced and may introduce memory management topics into articles and blog posts that the author doesn't want to cover. But I agree, once you use array-backed lists, the common examples of linked lists you can find online where new is used twice per node, once for a generic node, and once for the payload, seems ridiculously wasteful. This is the kind of thing I meant earlier - best practice would be to avoid a naive bad linked list even in code that isn't a hot spot. Time doesn't have to be spent optimizing it, and it doesn't need to appear as a hotspot, to know it should be avoided.

[1] https://en.wikipedia.org/wiki/Linked_list#Internal_and_exter...

Re:The compiler will optimize that away by dahart on Monday May 03, 2021 @07:46PM (#27032365)
> at least the JVM most definitely doesn’t do that, and I’m sure other state-of-the-art GCs neither, like V8.

Which implementation are we talking about here? Do you mean JVM internal linked lists, or user allocations of linked list nodes? I was talking about implementations such as (first Google result for "Java linked list implementation") https://www.geeksforgeeks.org/implementing-a-linked-list-in-...

> First of all, allocation is basically free

No, definitely not true. You're claiming that memory allocation in a tight loop is not a bottleneck. I completely disagree, having written several high performance web apps with thousands to millions of users, the single most important performance "best practices" strategy in any tight-loop Javascript is to avoid memory allocation in the hot spot. Also true in Python, true in C++, true in every language I've ever used, and has been true for decades and is still true despite significant performance improvements in V8 and other engines. This is the whole reason there are high performance libraries in JavaScript like https://glmatrix.net/ that specifically structure the API so that the user has complete control over allocations, precisely because batching and re-using allocations is faster than not.

Re:The compiler will optimize that away by kaba0 on Tuesday May 04, 2021 @03:08AM (#27034774)
What are the specific situation that we are talking about? Of course needless creation of non-single-use objects will have a cost, but object reuse via pools may be even worse than creating non-escaping objects in a tight loop. The “problem” with high level languages is the complexity of their runtimes - you can’t easily reason about what and how will get optimized. It can change from version to version so one should profile.

Not too familiar with JS vm internals, but OpenJDK has quite a good escape analysis.

Re:The compiler will optimize that away by dahart on Tuesday May 04, 2021 @02:15PM (#27040757)
> The “problem” with high level languages is the complexity of their runtimes - you can’t easily reason about what and how will get optimized.

Yes, agreed. This is the point the author was making, and noting that we have room to actually improve the languages, and make some basic optimizations easier to think about and code explicitly.

> object reuse via pools may be even worse than creating non-escaping objects in a tight loop.

When does this happen in practice, and how likely is it? What does it imply about object lifetime if your objects don't escape, and why wouldn't you be re-using an object on the stack or local scope instead? How often would replacing a non-escaping object creating with a re-use that escapes be a realistic alternative? I'm sure a contrived case can be setup, but this seems like an unlikely explanation to me as general advice. It's bad practice to hope your objects don't escape, and difficult to ensure. In general, if you want higher performance, then avoid using new in hot spots. The difference is often an order of magnitude in an flat O(n) loop.

Re:The compiler will optimize that away by kaba0 on Tuesday May 04, 2021 @04:03PM (#27042216)
I’m not disagreeing with you, and as a very general advice, less allocation is better of course.

My point was more along the way that sometimes very non-intuitive (from a low-level perspective) solutions may optimize better, because that’s what the compiler writers optimized for.

And object pools at least in Java is not necessarily good. The first go at it should be the plainest implementation one can imagine (on a micro level. Of course architecturally it is important to think about optimization, like whether it will be a class or an array, etc.)

Re:The compiler will optimize that away by desperate on Monday May 03, 2021 @05:26PM (#27030888)
Slightly off topic but I just realized that not only does optimized code = less processor cycles but less cycles = less power used.

This brings two rhetorical questions, How much more effective compute would we have if all code running today were perfectly optimized, and how much less energy would be needed under the same circumstances?

The computer gains could only be used in networks where unused compute can be scheduled / sold to other tasks. The energy gains could only be reaped if processors had proper low power modes they could fall into or some other method of conservation.

Re:The compiler will optimize that away by aspaceman on Monday May 03, 2021 @11:37AM (#27026438)
High performing code doesn’t have to be hard to reason about.

You wouldn’t say the plan for a safer building is harder to read.

People excusing their poorly written code as “highly-optimized” is the oldest cop-out we’ve got as programmers.