Pointer tagging encodes metadata into a word-sized pointer, aiding in efficient metadata storage within machine registers. Five methods of pointer tagging are discussed: lower bits, lower byte, upper byte, upper bits, and NaN boxing. The post compares their performance through various benchmarks, revealing optimizations are compiler and architecture-dependent, and highlights that memory management strategies often outweigh CPU instruction savings. Different tagging methods offer various trade-offs in terms of the number of tags and data storage capacity.
Table of contents
The types of tagged pointersTag 0Tag 1Check TagsFunction callsEliding pointer taggingBut what about floating point?So which is best?Sort: