4 ms·
Is this about premature optimisation or just good architecture? The number of data formats I see that miss obvious things like alignment etc. it isn't somethin
by benj111 4mo ago
Is this about premature optimisation or just good architecture?
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.
- jdw64 4mo ago>The number of data formats I see that miss obvious things like alignment etc. 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
- benj111 4mo agoIt doesn't even have to impact readability. See for example https://github.com/MayaPosch/NymphRPC/blob/master/doc/nymphrpc_protocol_specification.md 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.
- jdw64 4mo agoCool