You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use double color components this will quadruple the size of Color. It would be nice to use Float32x4 but Float32x4 is not const constructible despite being immutable. Using Float32x4 would make Color not const constructible which would be a huge breaking change.
There are performance benefits to storing things in Float32x4 too for things like colorspace conversions.
This isn't required for the the wide gamut work but it would be nice to have.
Summary: The Float32x4 class is immutable but not const constructible, preventing its use in Color for performance and size optimization. This limits the potential for Color to be const constructible, which would be a breaking change.
This will require special support in compilers and back-ends. A Float32x4 constructor requires doing conversion from double to 32-bit float, which Dart has no direct method for, and definitely no constant operation for.
The memory layout of a Float32x4 is not a normal Dart object, it's 128 bits of storage that's interpreted specially when accessed, and initializing that special storage at compile-time is a new feature that doesn't exist today.
Being immutable is not the same as being compatible with being constant. If the operations performed by the constructor aren't trivial, it's not just a normal const constructor.
Mraleph framed it well in the Dart discord. The gist is that Float32x4 is conceptually no different than something like a double or a string and the mechanism that is used to make those const constructible should be used for the SIMD types too.
Activity
dart-github-bot commentedon Aug 1, 2024
Summary: The
Float32x4class is immutable but not const constructible, preventing its use inColorfor performance and size optimization. This limits the potential forColorto be const constructible, which would be a breaking change.lrhn commentedon Aug 1, 2024
This will require special support in compilers and back-ends. A
Float32x4constructor requires doing conversion fromdoubleto 32-bit float, which Dart has no direct method for, and definitely no constant operation for.The memory layout of a
Float32x4is not a normal Dart object, it's 128 bits of storage that's interpreted specially when accessed, and initializing that special storage at compile-time is a new feature that doesn't exist today.Being immutable is not the same as being compatible with being constant. If the operations performed by the constructor aren't trivial, it's not just a normal
constconstructor.gaaclarke commentedon Aug 2, 2024
Mraleph framed it well in the Dart discord. The gist is that
Float32x4is conceptually no different than something like adoubleor astringand the mechanism that is used to make those const constructible should be used for the SIMD types too.rmacnak-google commentedon Dec 10, 2024
Somewhat related https://dart-review.googlesource.com/c/sdk/+/357440
modulovalue commentedon Jul 20, 2026
Duplicate of #31487