Skip to content

[web] [images] Optimize sized image loading #118985

Description

@tvolkert

In flutter-team-archive/engine#38905, we added the following API in dart:ui:

Future<Codec> instantiateImageCodecWithSize(
  ImmutableBuffer buffer, {
  TargetImageSizeCallback? getTargetSize,
});

typedef TargetImageSizeCallback = TargetImageSize Function(
  int intrinsicWidth,
  int intrinsicHeight,
);

This was easily implemented in the VM engine, but in the web engine, in order to know the intrinsic size of the image, we first have to create a codec, decode the first frame, and then extract the intrinsic width & height out of that frame. Then we consult the TargetImageSizeCallback for the target size, and we create another codec against the target size, discarding the first codec.

There's a possible optimization we could make whereby we could return the first codec (rather than discarding it and creating another) if the getTargetSize callback returned a target size that either (a) had both the width & height null, or (b) specified the same size as the intrinsic size.

In order to do this, we'd take advantage of the fact that the CanvasKit codec knows the width & height of the image without needing to get the first frame. We could expose that implementation detail encapsulated inside the web engine (without exposing the width & height to the public Codec API), thus allowing us to avoid getting the image's first frame - and in turn allowing us to return the codec directly rather than discarding it and creating another.

Activity

  1. added
    engineflutter/engine related. See also e: labels.
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    platform-webWeb applications specifically
    a: imagesLoading, displaying, rendering images
    perf: speedPerformance issues related to (mostly rendering) speed
    e: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Web
    P3Issues that are less important to the Flutter project
    on Jan 23, 2023
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

    P3Issues that are less important to the Flutter projecta: imagesLoading, displaying, rendering imagesc: performanceRelates to speed or footprint issues (see "perf:" labels)e: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webengineflutter/engine related. See also e: labels.perf: speedPerformance issues related to (mostly rendering) speedplatform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions