The Binary instance for TypeRep smells a bit expensive
getSomeTypeRep, in turn, calls
typeRepKind through its recursion. But
typeRepKind is itself recursive, fully inspecting the spine of its argument. That smells quadratic to me. The solution, I believe, is to change the type of
BinHandle -> IO (SomeTypeRep, SomeTypeRep).