mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-11 02:03:59 +08:00
A shape union's tag helper switched on the record's shape number. Inlined into a caller's branch on the arm, LLVM folded the two into one jump table per site, spanning the arms' shape numbers. In the native compiler, whose IR unions span about 112 shape numbers, that came to about 27,600 tables and 9 MB of read-only data, most of which a cold build pages in. A union whose arms span more than 32 shape numbers now maps the shape number to its arm through one constant table, indexed by the shape number minus the arms' lowest. An entry is a byte, or a 16-bit word for a union of 255 arms or more; the all-ones entry names no arm. Callers branch on the small arm tag. Narrower unions keep the switch, whose folded jump tables stay small and dispatch in one jump.