Boxing とは?
boxing は、プリミティブや value type のデータを heap に確保したオブジェクトの中に入れ、参照として扱えるようにする処理で、オブジェクトを期待する generic やインターフェースを満たすためによく使われます。unboxing は、内部の値を取り出して戻します。この包み込みは、素の値の格納では避けられる割り当てと間接参照を追加します。
なぜ重要か
boxing により value type を参照ベースの API に流せますが、ホットパスでの過剰な boxing は割り当てと garbage collection の負荷を増やします。隠れた boxing を見つけることは、よくあるパフォーマンスチューニングの作業です。
関連ガイド
What Is Type Erasure?Type erasure discards specific type parameters at or after compilation, leaving generic code working through…
What Is Trait Object Dispatch?Trait object dispatch calls a method through a runtime pointer to a table of implementations, choosing behavi…
What Is Generational Garbage Collection?Generational garbage collection groups objects by age and collects short-lived young objects more often than…