elementTypeSample constant

int const elementTypeSample

How many elements _homogeneousElementType reads (SCF28).

A native collection carries no element type the interpreter can read back, so a declared List<T> is checked against the type its CONTENTS share. Reading all of them made every binding of a typed collection cost time linear in its length — measured 2026-09-22 at about 0.096 us per element per binding, half a millisecond for 5000 elements. Reading a fixed prefix makes it O(1): measured 2026-09-29, the overhead of List<int> v = c; over var v = c; is flat at about 4 us from 100 to 5000 elements, against 98 us and 474 us before.

The bound is 8 because of what the suites depend on, measured by running both interpreters' full suites with smaller bounds: at 1 exactly one case fails (F-SCD92-6, a heterogeneous [1, 'a'] whose disagreement is at index 1); at 2 and at 4 none does. 8 is that deepest index with a fourfold margin.

It changes one answer. Every homogeneous collection, and every one that disagrees within the prefix, is answered exactly as the full walk answered it. A collection that agrees for the whole prefix and disagrees later used to be "heterogeneous" and pass; it is now checked against the prefix's type — and refused only when that type is not the declared argument, i.e. only when an element is provably not a T, which Dart refuses too. The full walk never caught a wrong element anywhere: one disagreement made the whole collection pass.

Implementation

static const int elementTypeSample = 8;