regionKey

function regionKey
terrainSelect.ts:705
regionKey(region: RegionAddress) → string | number

A region as one number, for the maps the balance pass lives in.

Levels to twenty-two keep i and j under 2²², which packs a whole address into 3.2e15 — inside a double's 2⁵³ of exact integers, and free to compare. Deeper than that it falls back to a string, which is slower and correct.

The bound has to sit above what the streamer actually asks for, which is the mistake this carried: it was written at twelve on the reasoning that surfaceDetailFloor never returned deeper, and the band stack moved the floor to between twelve and sixteen across the zoo — seventeen on the worst generated body. Every selection deeper than twelve took the string branch, the fallback paying 1.8 ms a pass in the code whose whole purpose is to avoid paying it. Twenty-two is the deepest level whose i and j still fit, so the fallback is now unreachable rather than merely unlikely; MAX_REGION_LEVEL is 24 and the two levels past it keep the branch honest.

The reason this is not terrainPatchKey: the balance pass builds a key for every node's eight neighbors and for every ancestor of every node, which on a whole-disk selection is nine thousand of them per pass. Built as template strings that was 1.8 ms — sixteen times the cost of the traversal it is correcting, and over the frame budget by itself.

Exported for the streamer's own caches, which key by region for the same arithmetic-over-strings reason — its request filter names over a thousand regions a frame. The body is deliberately absent from the key: a cache that outlives its body is cleared, not disambiguated, and terrainPatchKey below is the spelling for the one consumer that does retain across bodies.

regionRegionAddress
Undocumented
Returnsstring | number