This looks incredibly useful and I appreciate the focus on performance. I often avoid writing helpers for type checking edge cases due to performance concerns, but you've done the hard work for me. Thank you.
It is very highly optimized, as performance was of critical importance.