Hacker News new | ask | show | jobs
by dmoy 712 days ago
Well in the articles case, it's the linked list `next` pointers:

https://mazzo.li/posts/value-speculation.html#value-speculat...

In a happy case, those will be laid out sequentially in memory so you can guess the value of the pointer easily.

(That said your comment still stands, since using linked lists in the first place is much more rare). But I suppose there's probably a lot of other domains where you might have a performance critical loop where some hacky guessing might work.

1 comments

Not only are linked lists rare, they are also mainly useful exactly in situations where you cannot guarantee a (even mostly) linear allocation order.
the optimization could be vaguely interesting if you are implementing a lisp (or some other list heavy language) and don't want to perform too aggressive non-local optimizations to optimize the layout of lists.
As I recall, at least one of the Lisp machine Lisps used a bit in the cons pair to declare if the cdr (tail element) was immediately following.

EDIT: https://en.wikipedia.org/wiki/CDR_coding

Memory pools are commonly allocated in a contiguous block and sliced into nodes placed onto a free list. They will be sequential until the pattern of allocations mixes them up.
Garbage collection is good at consolidating swaths of adjacent free objects into ordered allocation.
The point here is that this isn't guaranteed, it's that it is likely. And as the other commenters mention, it's likelier than you think.
The Linux kernel is full of links, and so are many (probably most) C programs in the GNU/Linux userland.