boricj
12 hours ago
I work with another team at work that uses lots of message passing, C++ virtual methods in deeply nested class hierarchies, large DOMs and off-the-shelf C++ STL containers... on a STM32MP1, which has an in-order Cortex-A7 and a pittance of cache.
On the other hand, in my team I wrote my custom C++ STL containers that allocate inline, SAX-style processing libraries and an object pool with links that use index+generations like 2000s video games... on a STM32H5 with less than a megabyte of RAM.
Mechanical sympathy feels like a lost art to people I demonstrate it to... and I had to demonstrate to the first team with benchmark numbers that I would not be the bottleneck between us by orders of magnitudes.
bunderbunder
11 hours ago
I’ve had code review pushback against reorganizing data structures to be more cache-friendly on the grounds that it was “premature optimization” even though I pre-emotively justified the decision with benchmark results indicating that the performance difference was large and business relevant, and addressed a real performance bottleneck that I observed during testing.
This was on a team and at a time where Clean Code was very popular. I somewhat wonder if the problem is that, in the 2010s, many people became convinced that certain aesthetic standards were both objectively, provably correct, and more important than anything else.
hinkley
9 hours ago
A lot of my poor opinion on developer opinions dates back to a couple projects where Product and Marketing were begging us for substantial performance improvements and the teams pushed back saying this was as fast as you could expect. I got 2x in the first six months on both projects, and delivered 25% per quarter on one for almost 2 years (that maths to around 8x) before I started to scrape the bottom of my barrel.
It’s predominantly a way to shut down thinking, which is why it’s so often misquoted. Knuth’s version is more nuanced. Theirs is not at all.
As a compromise I got really good at doing optimizations that also improved readability. Things like hoisting and better variable naming combined together can be mistaken for just code cleanup.
I also discovered that keyhole optimizations are more palatable. Which is to say, move the slow bit yo a separate function with a single responsibility. Then do the optimization in a separate commit. Then the other devs don’t have to look at your changes and if they turn out to have a bug, we can always revert the change later. They almost never do, but having the option seems to grease the wheels.
nomel
2 hours ago
My general rule of thumb is that if you see you can 2x it easily, you can actually get somewhere around 10x with effort, since the presence of that easy 2x means nobody really spent any time on performance.
vrighter
an hour ago
i got over 800 this way. O(n^2) everywhere and n+1 queries
jonathanlydall
43 minutes ago
This sounds like being completely performance oblivious, like an extreme opposite of premature optimisation.
My rule of thumb is that as long as it doesn’t really complicate or convolute the code, write with performance in mind.
My expertise is in C# and sometimes this is as simple as using a hash set or dictionary instead of a plain list.
Other times it’s having a decent understanding of how EF (an ORM) actually works (the static typing benefits of them in C# makes ORMs very valuable when used appropriately) and the cost of round trips to any network host (including a DB).
vrighter
25 minutes ago
a hashset was used... then ".Where(x=>x == key).Count() == 0"
rowanG077
3 hours ago
Nitpick but 25% improvement over 8 quarters is 1.25^8, almost a runtime in 1/6th of the time.
plasticchris
11 hours ago
That’s just pattern matching. Most people don’t do this level of prep so they assume you didn’t either. There’s usually no ill intent, and people are maybe a little embarrassed when you point it out, but if you are tactful it’s fine.
user
2 hours ago
dnautics
9 hours ago
> objectively
I see what you did there
Gibbon1
10 hours ago
Processors I mostly write firmware for have little cache at all.
I think cache friendly code also tends to be reason about friendly and debugger friendly. None of that is remotely premature optimization.
dataflow
10 hours ago
> I think cache friendly code also tends to be reason about friendly and debugger friendly.
Not sure what examples you have in mind, but the very first things I think of when I hear cache friendly code are cache-blocking and cache-oblivious algorithms, which are quite the opposite of that. See also B-trees vs. binary search trees, etc.
bunderbunder
6 hours ago
I usually start with simpler things like paying attention to locality of reference and adjusting data so that it takes up less space in memory.
jacquesm
8 hours ago
Even CPUs like the ARM cores have caches, usually 16K, occasionally 32K, and even larger L2 caches (512K).
sick_of_slop
11 hours ago
Before AI, nobody has been responsible for more psychic damage against software developers than Bob Martin.
teddyh
an hour ago
From what I understand, it is mostly the very rigid and prescriptive attitude which the average reader gets from his book, which, if you listen to him talk, was not his intent. He even published a new 2025 edition of “Clean Code” to try and fix this, by making the text less self-assured. So while he may or may not be responsible, he did not intend it.
gjvc
9 hours ago
think you mean "psychological damage". Can you give some examples of what you mean?
zbentley
8 hours ago
I’m not who you were replying to, but there was a thread here a couple of years ago in which many people chimed in with examples. I added my two cents here, but the whole discussion is much more worth reading than my gripes: https://news.ycombinator.com/item?id=43166836
bigstrat2003
7 hours ago
Psychic is a damage type in D&D (and probably other RPGs too), so that is most likely a reference.
gjvc
6 hours ago
[flagged]
gjvc
6 hours ago
[flagged]
AnimalMuppet
5 hours ago
"Can you give examples?" was perfectly reasonable. "Are you high?" is not.
Calling everyone who downvotes you "incels" is very much against site rules. You've certainly been here long enough to know that. Knock it off.
gjvc
an hour ago
comparing reality to board games in this manner is the product of an ill or festering mind
clivedup
10 hours ago
There's not enough context for me (or other commenters) to really evaluate this, but every change has risk, and some projects aren't in a position to be accepting that risk.
A "real performance bottleneck that I observed during testing" is a little bit unclear whether it occurred outside of test conditions, or whether speeding up that particular bit improves anything anyone cares about.
user
7 hours ago
jordand
12 hours ago
I work in the games industry with exceptionally skilled system programmers that can do that too. They're getting on in age, and there's fewer programmers in the younger generations that are interested in any of it. Technology is sadly increasingly homogenising around Unreal Engine 5
MisterTea
12 hours ago
> Technology is sadly increasingly homogenising around Unreal Engine 5
I kinda get the commodification of games engines and Unreal. I am sure a lot of us saw the gaming revolution unfold, watching gaming companies one-up each other in graphics and interactivity. But once you get to the point of UE5, Unity, or Godot there is little need or value to make a game engine from scratch anymore.
Don't get me wrong, if you want to write an engine, go for it. But if you just want to make a game then an existing engine is good enough.
Jtarii
11 hours ago
If everyone stops writing game engines then who is going to program unreal engine/unity/godot?
bunderbunder
11 hours ago
I’ll admit I lost the plot a long time ago, but there’s a part of me that wonders if the main purpose behind the game engine and graphics card treadmill is to line the pockets of people who sell games engines and graphics cards. My subjective sense of the connection between technology and enjoyment as a player started to degrade about a decade back.
Jtarii
10 hours ago
I think it was just studios competing with each other in the 2010s to see who could make the biggest most ambitious game worlds. Leading to ballooning dev costs and then a feedback loop of higher production costs leading to safer design decisions.
There was also a heavy emphasis on games being "cinematic" which necessitates photorealistic rendering.
AAA games have been pretty artless for a while now baring a couple exceptions.
bunderbunder
9 hours ago
It’s especially the “cinematic” bit that got me. It’s technically impressive, but isn’t as visually interesting as what lower budget games have been doing with less polygons and more inspiration.
unrented7977
10 hours ago
[dead]
alpaca128
10 hours ago
I'd it's more a convenient outcome of maximizing profits than premeditated. Not optimizing is cheaper for studios while Nvidia doesn't mind extra popularity for their DLSS feature.
Crysis 3 is over a decade old, still looks great and ran on hardware that wouldn't suffice for web browsing today. I haven't seen anything in games since then that justified a significant increase in system requirements.
ses1984
3 hours ago
What about hardware that could run crysis3 wouldn’t suffice for web browsing?
lelanthran
43 minutes ago
Well, it ran on my 9600GT, which I used in a desktop from 2016 and recently used that desktop with 16GB RAM for the last few weeks.
I was unable to see any site that used webgl, which is almost all games site and many charting and graphing apps.
immibis2
10 hours ago
The people working for Unreal/Unity/Godot. Nobody writes search engines any more - except for Google et al. Nobody writes advertising systems - except for all the advertising businesses.
fasterik
10 hours ago
Games are a bit different in that the game engine is a core part of the product. There aren't many projects with $100M budgets building directly on top of a search engine. A lot of small and medium sized companies will use off the shelf game engines, but you'll never see Rockstar switching over to Unity/Unreal.
Jtarii
9 hours ago
Okay, but google search has only gotten worse for decades.
So your argument is that game engines will just decay.
Emjayen
8 hours ago
Not unique to gamedev; during the boom at the turn of the millennium the bar to entry to programming was dropped on the floor to fill demand.
The vast majority of programmers today don't even understand the basics of how-computer-work - not just microarchitecural considerations but even how to interface with the kernel efficiently / understand the performance considerations of their target platform.
Ask your average programmer how to say, simply perform I/O efficiently as possible on NT given some workload characteristics. One needs to first understand this before they can begin making concessions in favour of other demands (abstraction, flexibility, ect) and very few programmers can even get beyond the starting line.
jacquesm
8 hours ago
I recently spent three weeks paring down a piece of software until it could run entirely in the L1 cache of the processor it was running on. The performance was - to put it mildly - impressive. And this was 1970's technology running on a modern CPU. This stuff can do miracles if you use it right.
fwlr
4 hours ago
Someone asked me why Zig programmers seem to genuinely enjoy passing the allocator around as an argument. I didn’t have a good answer at the time, but I think I do now, thanks to your comment - feeling the “weight” of allocations is an example of mechanical sympathy, and having to pass around and use an allocator explicitly makes your code-effort more closely resemble the chip-effort it is asking for.
kibwen
2 hours ago
Heap allocations aren't really the culprit of the waste that the root comment is talking about. Indirection in general is, and passing around an allocator doesn't guard you against that. Virtual dispatch occurs even for objects on the stack.
fwlr
2 hours ago
Yes, I was suggesting allocation as another example of the same principle.
immibis2
10 hours ago
If it has a pittance of cache, then mechanical sympathy might not mean cache-friendliness. Linked lists were mechanically sympathetic on uncached systems - it cost the same to access any byte of memory, so you might as well go directly to the one you wanted.
boricj
10 hours ago
Looking at the specs: 32 KiB of L1, 256 KiB of L2, in-order and partial dual-issue.
That's the least forgiving kind of chip when it comes to performance: fast enough to outpace main memory by two orders of magnitude, yet the slightest speed bump (branch misprediction, cache miss) stalls it without any ability to reorder around it.
brcmthrowaway
10 hours ago
What is a cache friendly version of linked lists?
Nevermark
10 hours ago
I thought up a RAM that paired every data word, with an address word, pointing to its "next" word. ListRAM.
Reduces usable RAM in half, but speed is speed.
The idea being the RAM buses could be designed to provide fast pipelines of chained data to the cache, despite arbitrarily scattering in RAM.
There is no way this could compete with a single batch read of actually adjacent data. But it could speed up "Random" accessed data, which often is not - in fact - actually random from the program's or the data structure's point of view, just not adjacent.
And it would do one thing better: Reading a null terminated string wouldn't over read. The null next-address would stop every small string read from becoming a page read.
Even more flexible, send little read-chain algorithms to RAM. A little address math chaining and branching on in-RAM values, on little distributed address-math cores (RAM embedded APU cores!), could avoid a lot slow turnarounds.
These kinds of ideas seem even better to me now, by orders of magnitude, than they did originally. RAM really needs help.
badlibrarian
9 hours ago
jiggawatts
8 hours ago
Similarly, if you squint at B-trees, they are just unrolled linked lists with "skipping".
Dylan16807
8 hours ago
B+ tree if you want unrolling, B-tree if you just want the faster random access.
user
8 hours ago
duped
5 hours ago
> mechanical sympathy feels like a lost art
Programs should express the solution, not the problem.