Premature optimization is fun sometimes
Posted by throawayonthe 2 days ago
Comments
Comment by jdw64 9 hours ago
Looking at this code, they saved one AND instruction and reduced a pipeline stall, but it seems like it would be harder for a future maintainer to understand, because not_received feels a bit less readable. I always think code that's easy for the computer to read and code that's easy for humans to understand are different things.
After writing my comment, I realized it came across as overly critical. But actually, I think this work is completely justified and beautiful. Honestly, it's at a level I couldn't achieve myself. I respect it.
Comment by srean 7 hours ago
That said, I agree with you that the maxim is often used to justify poor planning or absence of planning. Premature pessimization is bad too.
We don't have the bandwidth to test every micro-decision. That's what the learning of domain specific principles are for. Then some choices you reason through, some you test and when confronted with a perf problem, test those reasoning based choices that benchmarks point fingers at.
Comment by jdw64 5 hours ago
Comment by benj111 3 hours ago
The number of data formats I see that miss obvious things like alignment etc. it isn't something you can easily change later if it becomes widely used.
To me this post represents the minimum you should be thinking about when designing any kind of data structure/format.
The only time where I would say it strays into premature is inverting the received flag, but only because you're optimising it for a particular processor and in a way that isn't particularly obvious. The inversion can easily be hidden behind a function call.
Comment by jdw64 3 hours ago
After reading that sentence, I felt a little guilty. It's actually a basic principle of design, but in practice, I just don't pay much attention to it and only write code for readability
Comment by benj111 1 hour ago
See for example
https://github.com/MayaPosch/NymphRPC/blob/master/doc/nymphr...
There's an int8 in the middle of int32s knocking everything out of alignment. And it doesn't need to be because flags is int32 and only uses 4 bits.
Changing that doesn't have to impact readability. Makes it easier to process, makes a struct representation more compact.
Comment by TacticalCoder 55 minutes ago
The "don't do premature optimization" mindset is the reason why we've got monstrous Electron apps doing jack shit.
I hate that quote, I hate that mindset. It's the reason everything is bloated and sucks.
Comment by KaiserPro 9 hours ago
Its like writing a thriller where you are the main operative, heroically saving the day with your skill, foresight and tenacity.
The problem is, it sets a rigid path far to early that you are unwilling to move away from, either because you had ambitions for those empty stubs, or because the obvious solution means admitting that you current $thing is not as successful as it should be.
The problem I have found recently is that it bleeds into the training set that LLMs to use to make software. our platform is pretty well defined and has excellent metrics and logging that come for free.
But the LLMs are creating Otel forwarders with custom NATs transport, even though we have all of that for free already (and in the agents.md)
Comment by Const-me 3 hours ago
Because the class/structure only has a single uint64 field, the compilers are likely to pass value in a single general-purpose register. I believe that’s unlikely to happen for a structure with bit fields.
If you target AVX2 or newer you also have BMI1 and BMI2, intrinsics like bextr and bzhi are probably faster than whatever codes compilers are generating for bit fields.
Binary compatibility of bit fields is a moot point, using them at the API surface across compilers or languages is not ideal. A structure with a single uint64 field is very compatible.
Comment by gblargg 8 hours ago
Comment by account42 7 hours ago
Even if it is not aligned, an unaligned 8K array would be spread to three pages which is still worse than two.
Comment by rwmj 9 hours ago
Comment by chadgpt3 3 hours ago
Comment by razieloren 6 hours ago
Comment by ramon156 5 hours ago