Hi V8 team,

I’m working on a patch to add a C++ fast path for Array.prototype.flat
(2-pass: precompute output length, preallocate, then write directly).
This is modeled after JSC’s C++ implementation but adapted for V8’s
elements/protector model.

Summary of changes:
- Add runtime fast path for Array.prototype.flat
- Preconditions: FastJSArray + NoElements/ArraySpecies protectors intact
- Proxy/accessor/custom elements bail out to existing slow path
- Recursive flatten only when elements are JSArray; otherwise bail
- If length exceeds 2^53-1, throw TypeError (same as spec)

Why:
- Current implementation writes element-by-element via property creation.
- For large arrays / deep nesting, we can significantly reduce overhead.

Correctness:
- holes are skipped (no property), consistent with spec
- fallback is always used when protos/Proxy/accessors exist

Performance (single-run huge array):
- input: outer=20000, chunk=1024 (output length 20,480,000)
- d8 fast (with patch): 58ms
- d8 slow (NoElements invalidated): 924ms
- speedup: ~16x

Tests run:
- mjsunit/harmony/array-flat
- mjsunit/harmony/array-flatMap
- mjsunit/harmony/array-flat-species
- mjsunit/harmony/array-flatMap-species
- (additional large test run completed)

I can share the patch and more detailed numbers if helpful.
Is this direction acceptable, or would you recommend any constraints or
additional checks?

Thanks!

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/v8-dev/fa39a8c3-7aca-4c29-ac4b-bd34e70d44b6n%40googlegroups.com.

Reply via email to