Skip to content

Avoid calling Dart_New in engine - it's slow. #50997

Closed
flutter-team-archive/engine
#16838

Description

@jmagman

Devicelab cull_opacity_perf__timeline_summary test failing with 30 second timeout exception.

2020-02-18T15:06:37.185691: stderr: [  +37 ms] VMServiceFlutterDriver: Waiting for service extension
2020-02-18T15:06:37.354258: stderr: [ +168 ms] VMServiceFlutterDriver: Connected to Flutter application.
2020-02-18T15:07:06.827425: stdout: [+29473 ms] 00:30 �[32m+0�[0m�[31m -1�[0m: cull_opacity_perf �[1m�[31m[E]�[0m�[0m
2020-02-18T15:07:06.829451: stdout: [   +2 ms]   TimeoutException after 0:00:30.000000: Test timed out after 30 seconds. See https://pub.dev/packages/test#timeouts

cull_opacity_perf__timeline_summary_bcacd06_2.log

Failing on engine roll bcacd06

Activity

  1. goderbauer commented on Feb 19, 2020

    @goderbauer
    Member

    /cc @jason-simmons I believe you're the engine roll sherif.

  2. jmagman commented on Feb 19, 2020

    @jmagman
    MemberAuthor

    @jason-simmons says:

    The cull_opacity test regressed starting at flutter-team-archive/engine@4941ff7. A call to driver.traceAction is timing out in the benchmark's flutter_driver script.
    ...
    The getVMTimeline call made by flutter_driver is now taking 28.5 seconds. Before it was taking 18.7 seconds.

  3. dnfield commented on Feb 19, 2020

    @dnfield
    Contributor

    Right now working theory is that new dart API is logging more timeline events, making the timeline about 50% bigger, which is taking about 33% logger to download, and is just enough to make our timeout too short ot download the timeline.

    The bigger problem is that this also results in a 20% drop in performance on the benchmark. @jason-simmons @rmacnak-google and @bkonyi are going to sync up on that further.

  4. dnfield commented on Feb 19, 2020

    @dnfield
    Contributor

    We may want to consider reverting the upstream dart change that removed the API (dart-lang/sdk@082aece) and then revert flutter-team-archive/engine@4941ff7 unless we can figure out a way to make it not regress performance so much more quickly.

  5. changed the title [-]cull_opacity_perf__timeline_summary timeout failure[/-] [+]cull_opacity_perf__timeline_summary regression and timeout failure[/+] on Feb 19, 2020
  6. jason-simmons commented on Feb 19, 2020

    @jason-simmons
    Member

    The additional timeline events are coming from the Dart_NewStringFromCString call added to provide the name of the default private constructor.

    Tried patching DartWrappable::CreateDartWrapper to create the string once and use a persistent handle afterward. With that change the timeline size and the getVMTimeline latency now match what they were before flutter-team-archive/engine@4941ff7.

    However, the average_frame_build_time_millis metric for the cull_opacity benchmark is still around 20% higher for Dart_New compared to the old Dart_AllocateWithNativeFields API.

  7. dnfield commented on Feb 19, 2020

    @dnfield
    Contributor

    The cull opacity benchmark creates tons of objects every single frame.

    It seems like there's just now a lot more overhead from calling constructors on those objects where we used to not.

    It'd be interesting to see if we can figure out which constructors we're calling and if some of them are doing some unnecessary work - it'd also be nice if there was just some Dart API to avoid doing the double hop from native -> dart -> native -> dart to construct an object and initialize fields. It seems more likely to me that the double hop is what is hurting performance here rather than that some randomc onstructor is doing tons of work.

  8. 13 remaining items

  9. chinmaygarde commented on Feb 20, 2020

    @chinmaygarde
    Contributor

    Just for this benchmark or generally?

  10. dnfield commented on Feb 20, 2020

    @dnfield
    Contributor

    Generally. This benchmark was particularly affected, but we should avoid replacing the current fast path with a slow path - and there's no good way to refactor the current path AFAICT - unless there's some magic the VM can do to recognize this constructor is empty and the object has no fields to initialize and avoid doing any expensive lookups more than once.

  11. dnfield commented on Feb 20, 2020

    @dnfield
    Contributor

    Basically, we hit the path we're touching a lot on every frame, to pretty much do anything.

  12. chinmaygarde commented on Feb 20, 2020

    @chinmaygarde
    Contributor

    Generally. This benchmark was particularly affected, but we should avoid replacing the current fast path with a slow path...

    I meant go one step further and also make Dart_New unusable as there is no fast way of making it work. I could still bypass tonic and write code that uses Dart_New directly if you removed only CreateDartWrapper.

  13. jason-simmons commented on Feb 20, 2020

    @jason-simmons
    Member

    Tried running the cull_opacity benchmark with the dnfield/picture_dart branch on a Moto G4. The build_time_millis metrics were roughly equal to the current master that uses Dart_AllocateWithNativeFields.

  14. dnfield commented on Feb 20, 2020

    @dnfield
    Contributor

    flutter-team-archive/engine#16713 should cover enough of the regression to be landable again. I'll break out other parts of my larger patch into smaller PRs, since some stuff is requiring a bigger refactor (images and paragraph in particular).

  15. changed the title [-]Engine/Tonic/Dart wants a fast path for allocating dart objects with empty constructor bodies[/-] [+]Avoid calling Dart_New in engine - it's slow.[/+] on Feb 20, 2020
  16. dnfield commented on Feb 20, 2020

    @dnfield
    Contributor

    Repurposing this bug again - VM may be able to optimize Dart_New, but it seems like we have another work around available that would be preferable. Rather than opening a new bug, keep this one for the context.

  17. jmagman commented on Feb 20, 2020

    @jmagman
    MemberAuthor

    cull_opacity_perf failing again on 0b5667a

  18. bkonyi commented on Feb 20, 2020

    @bkonyi
    Contributor

    cull_opacity_perf failing again on 0b5667a

    That's a roll that only contains changes ~2 day old and doesn't contain the reverts.

  19. jmagman commented on Feb 20, 2020

    @jmagman
    MemberAuthor

    Looks like this issue was repurposed away from the cull_opacity_perf__timeline_summary test failure. I'll file a new issue.
    #51148

  20. added this to the March 2020 milestone on Mar 2, 2020
  21. github-actions commented on Aug 22, 2021

    @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.

  22. locked as resolved and limited conversation to collaborators on Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

dependency: dartDart team may need to help usengineflutter/engine related. See also e: labels.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions