Micro benchmark, reading the results
In the previous posts, I discussed various options for accessing a value through a pointer, either by using a casted pointer, or casting it whenever we need to use it.
The good news from the benchmark is that all results are close enough to one another to be effectively equal. That means that there really isn’t any difference between the two options.
Except, that there is. By only having to keep track of a single pointer field (instead of two fields, one that is byte* and one that is PageHeader*), we can save a field. That means that we save 8 bytes on every page we allocate. And we can allocate a lot of pages.
The end result is that the casting approach is much faster, not because it runs faster, but because it reduces the size of allocations we make. And reducing the size of allocation end up using less memory, which end up being faster overall.
Comments
But why do you have to keep two pointers pointing at the same location? Why PageHeader* field is not enough?
@OmariO Because PageHeader* is just the prefix of the page, then there is the data which can have variable size. PageHeader cannot contain variable size if you want it to be a blittable struct. In cases like Fixed size trees you can know the layout beforehand and code everything with blittable structs, but in cases where data is there you cannot control beforehand the layout.
Comment preview