A string can obey ECMAScript’s abstract model yet occupy a very different location in V8’s heap. Large Object Space is the separate heap region for allocations too large to fit within ordinary pages or young-generation semi-spaces. section 2.2.2 section 9.2.1
V8 divides the heap into pages, typically around 256 KB, that normally hold multiple heap objects. Each large object instead receives its own dedicated page sized to contain it. For strings, values below 128 KB remain on regular pages; larger strings move to Large Object Space. section 2.2.2
The placement decision changes the object’s collection lifecycle:
- Normal young-generation allocations can survive scavenges and later be promoted to the old generation. section 9.2.1
- Allocations too large for young-generation semi-spaces skip that path and enter Large Object Space directly. section 9.2.1
- Large allocations therefore carry old-generation collection costs from creation rather than receiving cheap young-generation collection first. section 9.2.1
A large string
Creating a string larger than V8’s 128 KB string threshold places it in Large Object Space instead of a regular heap page. The ECMAScript specification permits a far larger abstract maximum, but V8 enforces implementation and memory limits. section 2.2.2
Figure 9.3 V8 divides its heap into distinct spaces. The young generation contains two semi-spaces (from-space and to-space), only one active at a time. Objects that survive two scavenges are promoted to the old generation. Allocations too large for the young generation go directly to the large object space.
Trace how ordinary objects move through young and old generations while oversized allocations bypass that progression. section 9.2.1
