I needed fast reflection for a project — stdlib reflect was showing up clearly on the profiler in hot paths like ORM scanning and DI. So I started looking at what already existed, and came across reflect2.
The idea there is simple: instead of going through the official reflect API, the library reads Go's internal struct layout directly. That's fast. Right up until Go changes those internals. And it does — the map rewrite to Swiss Tables in Go 1.24 is a good example. When that happens, the library doesn't crash, doesn't panic, doesn't throw an error. It just quietly reads the wrong bytes. You won't notice right away — maybe a week later, maybe two months later, when weird values start showing up in production and you spend half a day figuring out where they came from.
That risk didn't sit well with me, so I decided to build the same thing, minus it.
What I ended up with
saferefl aims for the same kind of speed, but through a more honest route: generics, cached field offsets, and an unsafe layer that verifies its own assumptions on startup and falls back to a safe path if something doesn't line up — instead of silently reading memory it shouldn't.






