Skip to content

Make Float32x4 const constructible #56363

Open

Description

@gaaclarke

As part of adding wide gamut color support to Flutter I'm looking to migrate Color to hold floating point values.

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.

Activity

  1. dart-github-bot commented on Aug 1, 2024

    @dart-github-bot
    Collaborator

    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.

  2. added
    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
    triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.
    type-enhancementA request for a change that isn't a bug
    on Aug 1, 2024
  3. added
    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
    and removed
    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
    triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.
    on Aug 1, 2024
  4. lrhn commented on Aug 1, 2024

    @lrhn
    Member

    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.

  5. gaaclarke commented on Aug 2, 2024

    @gaaclarke
    ContributorAuthor

    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.

  6. rmacnak-google commented on Dec 10, 2024

    @rmacnak-google
    Contributor
  7. modulovalue commented on Jul 20, 2026

    @modulovalue
    Contributor

    Duplicate of #31487

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-typed-datatype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions