What if the language has a bad design?
Programming
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
Then use it poorly and it's a double negative.
Every method just returns an empty string. Runs fast as hell. Just don't expect it to do anything.
Both matter...
Has everyone forgotten the art of creating or using performance profiling tools
I was in a meeting with a senior software engineer, who makes a shit ton more than me. While sharing my screen he saw flame graph I had for one program I was working on. They asked "what is that?", I was taken back, and said it's for looking at which functions are taking more time. Then I was asked "where did you find it?" I was shell shocked, didn't know how to answer that. Similar things have happened before where I taught them certain things, and they go "great find", like dude, I didn't find it just now. That's basic knowledge if you work with database.
I am not even a developer hire, I'm self learned, and because the company doesn't have many developers they gave me some of the tasks and I'm doing it because it's more fun than my job responsibilities, and when I don't have enough tasks.
You see, performance is rarely a talking point in retrospectives unless its egregious. If you say a piece of compute is struggling the solution is to always buy more compute. It is rare that anyone would think of optimization unless you're writing libraries.
Or if its employee facing only let it get slower and slower to the point where it takes a minute to update one record
Which is exactly why western AI companies are bankrupting themselves building data centers while China is easily keeping pace with a fraction of the resources. They're not magic. They just do basic things like make things more efficient.
I think that's one of the problem with people that are only of a "finish this task cheaply for now" mind.
Having something run in 0.1 second vs 1 second is fine when a user is running it for one thing. So they consider it good or instantaneous. And later they have to do it for 1000 other things, and they don't think that saving time in that "instantaneous result" there would save so much more time. They just go "it's 1000 of these so it takes time". I've found functions that open a db file, read one entry and close it. Then that function is called for each entry they have to read later. In a preprocessing step where they know all the entries they need beforehand. And even the data tyoe to store it is nor preallocated, they just append it on every data read; again on a fixed number of entries they need.
I understand performance not being the most important thing, but I'd expect least a basic understanding of design that has unnecessary processing.
Flame graphs have really only been a thing for the last decade or so. The free tooling for profiling code has been shitty and difficult to understand for most of my career. And most companies aren't willing to pay for it if the product runs "good enough". These days companies lock down their shit so tight that you can't even install an unapproved app no matter how free or useful.
I think that's true for many tools. Programming tools are the one thing that has most advancement because so many programmer are there to improve on them. And even if you don't use it, not knowing about it completely makes it a bit odd. Although most tools I have used to make flamegraph were as easy as just running the program as a argument to another program that tracks the function calls.
Ive used them to help a lot in the past, but they often didnt give enough detail. Like I would know the area something was a problem, but pinpointing exactly what it was was still up to me, and would take some time. It worked but it could have been better.
Turns out there was a library you can add which adds that extra missing detail, and with that it was possible to highlight the exact issue. Wish id known about that sooner. That was on me though.
Pay me to do it and I'll gladly do it. Most companies, however, don't really care much about whether the customers take an extra 100 milliseconds for every request or not. And when it's promotion time, you're often judged by how many tasks you get done, not how fast your code is.
Too many abstraction layers
I wrote a program in Python to read some huge Json files. It took forever to finish. Turned out I could optimize it with some simple changes, which reduced 10 minutes to 10 seconds (not literally, just figurative) and made a difference in huge files only. Later I rewrote the program in Rust. And you know what happened? It was slower than the Python version. Only after understanding what I was doing and making right changes made the Rust version faster.
Most of the time its the design of the code or libraries that slows down. The language might play a huge role in performance, but it depends on what type of code and application it is.
I actually wanted write a blog post about this... if I still have the project data I might explain what happened. BTW this had nothing to do with Ai.
yeah, sometimes it feels like the same people complaining about python speed are the ones writing "C" code in python.
The thing is also that you can't separate a language from its ecosystem.
Because it is possible to write the fastest programs in C/C++ and Rust, folks that actually need the fastest performance will use these languages and will go around opening pull requests to fix performance problems in commonly-used libraries.
So, you do often end up with the most performant design anyways, just because the language itself is fast on paper.
I'd add that most of the time nobody actually measured anything. at work we inherit slow sites all the time and the first guess is always "the stack", then you profile it and it's one query running per item in a loop or something like that. I had the same with my own side project, was sure I needed a bigger server and after measuring the problem was somewhere else completely. measuring first is boring but it's cheaper than any rewrite I guess
Profiling complex systems can be quite difficult. That said, I believe in the adage "Profile twice, optimize once.", adapted from the old carpenters adage of "Measure twice, cut once."
Slowness is rarely essential, but I can be far away from where you expect it.
That's what Open Telemetry is for, honestly, specifically tracing. I'm in the process of adding tracing for all of our web handlers, http client calls, database transactions/individual queries, and asynchronous jobs. Should give us a pretty good view into the performance of the system, and allow us to monitor for things like performance regressions without any dedicated profiling needed (though we certainly could add additional profiling information through Otel down the road). Since I know you're a Haskeller (recognize your handle), the hs-opentelemetryecosystem is quite solid and has integrations with a lot of libraries in the wider ecosystem, like wai, persistent, postgresql-simple, conduit, and a bunch more. I haven't needed to write too much of our own instrumentation, aside from our job system since that's a bespoke system.
Noticeable speed? Sure. But I am so pissed if a fucking todo list app is a 100mb download and consumed 300mb memory when running, all because this fucker bundles and loads a whole browser engine to render itself.
I therefore do think tech stack matters as well.
Web development and using browser renderers for GUIs is one of my most hated aspects of modern software. 🤢
Electron should have never existed and should be cometeñy banned, yeah
Sorry guys, back in 2008, I asked a monkey's paw for better first party software support for desktop Linux, and this is what we got.
Ship in the minimum amount of time possible, by any means, to be first to market. And this means poor design and smooshing together all kind of fat general-purpose frameworks and libraries to get something out the door.
Sure, it's slow. Google's landing page is 4 MB for a small graphic, a text form, and some buttons. But what are you going to do? Not use it? They won. They don't have to fix shit.
And now with LLMs they can produce bloat faster than ever and pay even less attention to speed or quality.
"The goal was never quality software."
Nah, software is slow because it runs a web engine for GUI.
I'd say a bit of both. People who are fine with having a DOM worth of overhead don't give me much confidence they are selecting algorithms well, which can absolutely affect performance and efficiency regardless of what language they are written in.
Hell, even with the optimal data structures and algorithms selected, how you set them up can make a huge difference.
Like I once had essentially a data translator that, in order to be generic, used keys in a dictionary to replace the hardcoded data structure that needed to be updated any time the spec changed, even if we didn't care about the new values.
The first version used an array of dictionaries and was slow as fuck. Each line of data would get its own dictionary and just parsing the data into this scheme took a couple minutes IIRC. Since the data was guaranteed to have the same keys each line (we were worried about changes between versions, not lines), I changed it to a dictionary of arrays, where each line would have the same index across the dicts, and it brought parse time down to several seconds. Huge difference even though big O notation would have simplified to the same expression for the two methods.
But if you pick something with a worse big O expression, it gets worse on a whole other level.
I worked at a place where a site had to show the number of members, but for some reason it didn't show the correct number. The reason was the query to the database was wrong, I corrected it in five minutes and the boss told me to put numbers manually, increasing them until we could display the correct query result because apparently the problem was there a long time before I started working there and it would make a bad image for the company if it was so easily corrected.
On other project a friend of mine told me about things were so slow and getting slower with time. Database didn't have keys, indexes, nothing you should expect a relational database to have.
I haven't worked in a while because of my health issues and I can assure you I'd be happier getting paid for watering plants than working with computers.
Software engineer and can confirm this is mostly the case. Adding a spinner or cute animation to placate users is way easier than solving fundamental issues. There are definitely teams out there that absolutely care about performance but mostly in large scale scenarios where an extra 10ms per record adds up to 3 extra hours to finish a batch.
Right now everyone is asking their AI agents to rewrite programs in Rust or C or assembly. This is fun, but it’s not a serious attempt at optimization.
C or assembly seems pointless and only for performance. But the reason people (re) write programs in Rust is because Rust as a language has a lot of guardrails that help make a program more stable, more correct. That reliability is the real reason for Rust. The performance is just a cherry on top.
This is actually exactly what you want in a language for AI. This is anecdotal from my side, but in my experience, an AI writing Rust will write far less sloppy crap than an AI writing Python.
Most of the argument against Rust has historically been that prototyping is slow and the language is a bother to write because the compiler makes it hard. But this only holds if humans are the bottleneck for writing the code! Rust therefore has all of the benefits but basically none of the downsides when having an AI write it.