Overhauled serializer to do less work in the critical serialization path.