Skip to content

Regression in frame build time in complex_layout_scroll_perf #130339

Closed

Description

@zanderso

SkiaPerf is reporting that the 90%-ile and average frame build time regressed on complex_layout_scroll_perf_bad_ios__timeline_summary by about 30%:

https://flutter-flutter-perf.skia.org/e/?begin=1688490769&end=1689086966&keys=Xfce5bf9b2126b8e2e20d155f0f31b1d5&requestType=0&selected=commit%3D35614%26name%3D%252Carch%253Dintel%252Cbranch%253Dmaster%252Cconfig%253Ddefault%252Cdevice_type%253DiPhone_11%252Cdevice_version%253Dnone%252Chost_type%253Dmac%252Csub_result%253D90th_percentile_frame_build_time_millis%252Ctest%253Dcomplex_layout_scroll_perf_bad_ios__timeline_summary%252C&xbaroffset=35614

The report is on the commit here 3b8f6c4, containing a Skia roll with unrelated commits, and a manual Dart roll flutter-team-archive/engine#43472 with commits here:

https://dart.googlesource.com/sdk.git/+log/2d98d9e27dae..0b07debd5862

Unfortunately, it's a large Dart roll with many VM changes. Marking P0 only for help with identifying any culprits, if possible.

Activity

  1. added
    c: regressionIt was better in the past than it is now
    engineflutter/engine related. See also e: labels.
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    perf: speedPerformance issues related to (mostly rendering) speed
    P0Critical issues such as a build break or regression
    on Jul 11, 2023
  2. zanderso commented on Jul 11, 2023

    @zanderso
    MemberAuthor

    The flagged framework commit also updated framework package dependencies, but I'm only seeing updates to dev dependencies, and not regular dependencies of the framework, so I wouldn't expect those updates to have affected frame build times.

  3. jason-simmons commented on Jul 11, 2023

    @jason-simmons
    Member
  4. lrhn commented on Jul 11, 2023

    @lrhn
    Contributor

    There are other mentions of the effect of this change on VM optimization.
    See dart-lang/sdk#48282 for discussion.

    The existing code was wrong, as in the iterator giving completely wrong results in some cases, so it's not just something we can revert.

  5. rakudrama commented on Jul 11, 2023

    @rakudrama
    Contributor

    For the benchmark to regress 30% on https://dart.googlesource.com/sdk/+/d8fa6fe25522f45b7070278ad152abe4724cbdf2 it must be doing almost nothing except iterating the .keys or .values of an empty Map.
    Our worst other regression was a micro-benchmark that did nothing other than iteration of singleton Map's .keys and was nearer 10%.

    This seems a little unlikely, so can you validate the finding by profiling before and after to identify where the time is going?

  6. jason-simmons commented on Jul 12, 2023

    @jason-simmons
    Member

    I can reliably reproduce the effect of https://dart.googlesource.com/sdk/+/d8fa6fe25522f45b7070278ad152abe4724cbdf2 on the complex_layout_scroll_perf_bad_ios__timeline_summary frame build time metrics.

    I tried capturing some profiles of the app used in the benchmark and noticed that it's spending significant time in Layer._fireCompositionCallbacks.
    (https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/rendering/layer.dart#L175)

    That function is iterating over a map that is apparently always empty in this app. It consumes a lot of the time that is accounted as "frame build time" in the benchmark.

    If I patch Layer._fireCompositionCallbacks to skip the iteration if the map is empty, then average_frame_build_time_millis is reduced by 25%.

    @a-siva Adding the @pragma('vm:prefer-inline') annotation to the _CompactIterable iterator getter did not have a major effect.

  7. mraleph commented on Jul 12, 2023

    @mraleph
    Member

    Comment dart-lang/sdk#48282 (comment) describes the reason for the regression. tldr here is that _CompactIterable.iterator now has two additional virtual calls. This would only matter if you are iterating really small maps (~1 element) so the overhead of creating the iterator dominates the rest. I am going to look at fixing this, but in the interim I suggest just skipping the iteration altogether.

    Also it's interesting that iOS regressed but Android did not?

  8. lrhn commented on Jul 12, 2023

    @lrhn
    Contributor

    Maybe the Android version is JIT compiled. I believe Android supports both AoT and JIT, where iOS only supports AoT.

  9. mraleph commented on Jul 12, 2023

    @mraleph
    Member

    Maybe the Android version is JIT compiled. I believe Android supports both AoT and JIT, where iOS only supports AoT.

    I am pretty sure Flutter only runs benchmarks in profile mode (which corresponds to release AOT in Dart parlance).

  10. chinmaygarde commented on Jul 17, 2023

    @chinmaygarde
    Contributor

    The regression is expected but a small amelioration has landed in #130438. Closing.

  11. github-actions commented on Jul 31, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Jul 31, 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

    P0Critical issues such as a build break or regressionc: performanceRelates to speed or footprint issues (see "perf:" labels)c: regressionIt was better in the past than it is nowdependency: dartDart team may need to help usengineflutter/engine related. See also e: labels.perf: speedPerformance issues related to (mostly rendering) speedteam-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions