Skip to content

Lightweight engines use significantly more memory for loading fonts #143701

@jiahaog

Description

@jiahaog

See jiahaog/bug_font_memory_multiple_engines@b794f25 for a Flutter app that can be used to repro this.

In release mode on a Pixel 6a, I collected the following profiles with the Perfetto Heap Profiler. We need to use a local unstripped engine build so that symbols from libflutter.so can be symbolicated. A userdebug build for the device may also be needed.

The number of engines can be toggled through this constant here.

  1. Install the app, then close it.
    flutter run \
      -d 'Pixel 6a' \
      --release \
      --local-engine=$HOME/dev/engine/src \
      --local-engine=android_release_unopt_arm64 \
      --local-engine-host=host_release_unopt
  2. Run
    tools/heap_profile -n com.example.bugfontmemory
  3. Start the app, wait 20 sec
  4. Press ctrl-c in the terminal to stop recording.

Profiles:

Actually the perfetto UI is unable to handle such deeply nested stacks, but should be able to download the profiles, open it with pprof to see the following:

image

Observe that in the screenshot, for flutter::AssetManagerFontStyleSet::createTypeface(int), the difference here is 4.711 MiB (many engines) vs 1.577 MiB (single engine).

As mentioned by @dnfield, this is likely due to flutter/engine#34473.

This is with:

Flutter 3.20.0-10.0.pre.11 • channel main • git@github.com:flutter/flutter
Framework • revision a603a17875 (3 days ago) • 2024-02-16 09:43:50 +0200
Engine • revision dd530f1556
Tools • Dart 3.4.0 (build 3.4.0-148.0.dev) • DevTools 2.33.0-dev.6

See also http://shortn/_afwYysWZou for more details internally. I have also attached links to uploaded profiles onto pprof there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listcustomer: googleVarious Google teamsengineflutter/engine related. See also e: labels.perf: memoryPerformance issues related to memoryplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions