1103
Tell me the truth ... (piefed.jeena.net)
you are viewing a single comment's thread
view the rest of the comments
[-] 30p87@feddit.org 86 points 2 days ago

Then you need to ask yourself: Performance or memory efficiency? Is it worth the extra cycles and instructions to put 8 bools in one byte and & 0x bitmask the relevant one?

[-] zea_64 22 points 2 days ago

A lot of times using less memory is actually better for performance because the main bottleneck is memory bandwidth or latency.

[-] timhh@programming.dev 2 points 1 day ago

It's not just less memory though - it might also introduce spurious data dependencies, e.g. to store a bit you now need to also read the old value of the byte that it's in.

[-] anton 1 points 1 day ago

It might also introduce spurious data dependencies

Those need to be in the in smallest cache or a register anyway. If they are in registers, a modern, instruction reordering CPU will deal with that fine.

to store a bit you now need to also read the old value of the byte that it's in.

Many architectures read the cache line on write-miss.

The only cases I can see, where byte sized bools seems better, are either using so few that all fit in one chache line anyways (in which case the performance will be great either way) or if you are repeatedly accessing a bitvector from multiple threads, in which case you should make sure that's actually what you want to be doing.

load more comments (1 replies)
load more comments (2 replies)
load more comments (7 replies)
this post was submitted on 15 May 2025
1103 points (100.0% liked)

Programmer Humor

23310 readers
1609 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS