3 ms·
For structs where there are only a dozen or so in memory at any one time, this makes sense. For structs where there are thousands, or millions, in memory using
by andrewprock 10y ago
For structs where there are only a dozen or so in memory at any one time, this makes sense.
For structs where there are thousands, or millions, in memory using the smallest type required to get the job done will improve performance because you will fit more data into the cache.
- mikeash 10y agoOnly if makes the overall structure actually becomes smaller. A bunch of these shorts were surrounded by fields whose alignment means that changing to int results in no increase in the overall size of the structure. In fact, I think some of them actually got smaller due to reordering the fields to be more alignment-friendly.
- andrewprock 10y agoStruct packing is something you can control at the compiler level. In gcc, you can add __attribute__((__packed__)) to your structs.
- mikeash 10y agoThat can add a performance penalty. If it didn't, compilers would always pack tightly, after all. In any case, these particular structs don't have any special packing applied.