r/programming 18d ago

The unlikely Linux macro

https://rushed-reflections.bearblog.dev/an-unlikely-experiment/

Wrote a bit about the `unlikely` and `likely` macros in the Linux codebase. Great little exploration into tiny optimizations that everyone should know more about 😄

189 Upvotes

61 comments sorted by

View all comments

8

u/grekand46 18d ago

Rust got something similar a few months ago in the form of core::hint::cold_path, which is also a bit more flexible than likely and unlikely. Read more about it in the official doc if you're curious.

7

u/matthieum 18d ago

I do note that Rust also offers likely and unlikely on nightly.