Skip to content

chore(immutable): set resolution - #720

Merged
Pavel Glac (pavelglac) merged 2 commits into
mainfrom
user/pavelglac/set-resulution
Aug 28, 2026
Merged

chore(immutable): set resolution#720
Pavel Glac (pavelglac) merged 2 commits into
mainfrom
user/pavelglac/set-resulution

Conversation

@pavelglac

Copy link
Copy Markdown
Contributor

Root cause
List stores its values in a 32-wide trie (SHIFT = 5, so each level addresses 5 more bits) and uses signed 32-bit bitwise arithmetic throughout setListBounds() (src/List.js):

Infinite loop (the hang / OOM). The level-raising loop
while (newTailOffset >= 1 << (newLevel + SHIFT)) {
newRoot = new VNode(
newRoot && newRoot.array.length ? [newRoot] : [],
owner
);
newLevel += SHIFT;
}
relies on 1 << (newLevel + SHIFT). A JavaScript shift count is taken mod 32, so once newLevel + SHIFT reaches 31 the term goes negative (1 << 31 === -2147483648) and at 32 wraps to 1 (1 << 35 === 8). The comparison then stays true forever and the loop never terminates. On a populated List, each iteration retains a new VNode ([newRoot]), so the heap fills and V8 aborts; on an empty List it spins on CPU without allocating.

Silent wraparound (the setSize corruption). The begin |= 0 / end |= 0 coercion (ToInt32) silently wraps large finite values ((2 ** 31) | 0 === -2147483648, (2 ** 32 + 5) | 0 === 5), producing a wrong resulting size instead of an error.
The threshold is 2 ** 30: that is the largest size for which 1 << (newLevel + SHIFT) stays a valid positive 32-bit integer throughout the loops (newLevel + SHIFT stays ≤ 30).

@celiac747
celiac747 self-requested a review August 26, 2026 09:19
@celiac747 celiac747 closed this Aug 26, 2026
@celiac747 celiac747 reopened this Aug 26, 2026
@pavelglac
Pavel Glac (pavelglac) force-pushed the user/pavelglac/set-resulution branch from a939e22 to 2ad4dd0 Compare August 27, 2026 09:29
@pavelglac
Pavel Glac (pavelglac) merged commit dfd5db1 into main Aug 28, 2026
6 checks passed
@pavelglac
Pavel Glac (pavelglac) deleted the user/pavelglac/set-resulution branch August 28, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants