Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in flutter microbenchmarks #17963

Closed
floitschG opened this issue May 28, 2018 · 4 comments · Fixed by #18163
Closed

Exception in flutter microbenchmarks #17963

floitschG opened this issue May 28, 2018 · 4 comments · Fixed by #18163

Comments

@floitschG
Copy link
Contributor

When running Flutter's microbenchmarks the error below (at the end of the bug-report) is printed on the console.
Due to timing issues, this error is handled differently with sync-async and makes the benchmark go red.
I'm adding a work-around to the benchmark, but that just treats the symptom.

I have debugged this. Here are my findings:

  • lib/stocks/layout_bench.dart runs the following statements in a loop:
      Timer.run(() { ui.window.onBeginFrame(new Duration(milliseconds: iterations * 16)); });
      Timer.run(() { ui.window.onDrawFrame(); });
  • The onDrawFrame depends on onBeginFrame to set _doDrawThisFrame to true or false.
  • Normally these functions are only called from the loop, but from time to time they are also called from the framework. This can be seen by observing the stacktraces.

This stacktrace is printed when called from the loop (line numbers might be off because of debug lines).

[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #0      LiveTestWidgetsFlutterBinding.handleBeginFrame (package:flutter_test/src/binding.dart:1011)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #1      _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:834)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #2      main.<anonymous closure>.<anonymous closure> (file:///usr/local/google/home/floitsch/code/flutter/flutter/dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart:65)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #3      _rootRun (dart:async/zone.dart:1122)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #4      _CustomZone.run (dart:async/zone.dart:1023)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #5      _CustomZone.runGuarded (dart:async/zone.dart:925)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #6      _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #7      _rootRun (dart:async/zone.dart:1126)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #8      _CustomZone.run (dart:async/zone.dart:1023)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #9      _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #10     Timer._createTimer.<anonymous closure> (dart:async/runtime/libtimer_patch.dart:21)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #11     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #12     _Timer._handleMessage (d

This stacktrace is the one from the framework (line numbers might be off because of debug lines):

[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #0      LiveTestWidgetsFlutterBinding.handleBeginFrame (package:flutter_test/src/binding.dart:1004)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #1      _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:834)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #2      _invoke1 (dart:ui/hooks.dart:134)
[microbenchmarks] [STDOUT] [        ] I/flutter (21815): #3      _beginFrame (dart:ui/hooks.dart:105)

For some reason the framework sometimes invokes handleBeginFrame and doDrawFrame. However, if these calls happen in the middle of the two Timer.run, then the second Timer.run call will have an exception.

Here is the exception that is thrown and printed on the console.
The following command was used: dart bin/run.dart -t microbenchmarks

[microbenchmarks] [STDOUT] [+1554 ms] I/flutter ( 3592): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): The following assertion was thrown running a test (but after the test had completed):
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): Failed assertion: boolean expression must not be null
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): 
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): Either the assertion indicates an error in the framework itself, or we should provide substantially
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): more information in this error message to help you determine and fix the underlying cause.
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): In either case, please report this assertion by filing a bug on GitHub:
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592):   https://github.com/flutter/flutter/issues/new
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): 
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): When the exception was thrown, this was the stack:
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): #0      LiveTestWidgetsFlutterBinding.handleDrawFrame (package:flutter_test/src/binding.dart:0)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): #1      _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): #2      main.<anonymous closure>.<anonymous closure> (file:///usr/local/google/home/floitsch/code/flutter/flutter/dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart:51)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): #11     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): #12     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): #13     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): (elided 8 frames from package dart:async)
[microbenchmarks] [STDOUT] [        ] I/flutter ( 3592): ══════════════════════════════════════════════════════════════════════════════════════════════════
@Hixie
Copy link
Contributor

Hixie commented Jun 1, 2018

Answering questions from e-mail:

  • What triggers the calls from the framework (from lib/ui/window/window.cc:253 - Window::BeginFrame

I assume you mean from the engine. The calls are scheduled when window.scheduleFrame() is called, and they are actually called when the engine decides that it's time to draw a frame (e.g. in response to an OS vsync signal).

  • What was supposed to stop these calls?

Nothing stops them.

  • What are possible avenues to explore why these calls are still happening.

I imagine these calls are happening because the engine decides it's time to render a frame.

Previously, it seems that scheduling two timers back to back would always end up scheduling these frames into back-to-back tasks with no chance of the engine doing its stuff in between (either that, or this test is slightly flaky, maybe?).

In any case, it looks like it should be pretty straight-forward to adjust this test so that we set window.onBeginFrame and window.onDrawFrame to null before the while loop, and then instead of calling them, we call binding.handleBeginFrame and binding.handleDrawFrame directly.

@floitschG
Copy link
Contributor Author

Previously, it seems that scheduling two timers back to back would always end up scheduling these frames into back-to-back tasks with no chance of the engine doing its stuff in between (either that, or this test is slightly flaky, maybe?).

No. We had these exceptions already. They were just ignored by the testing framework (I'm guessing because they were delayed enough).

@Hixie
Copy link
Contributor

Hixie commented Jun 1, 2018

Ah, interesting.

christopherfujino added a commit to christopherfujino/flutter that referenced this issue Apr 28, 2020
0c35a34 Roll src/third_party/skia f5132a05c893..4baa7326ccfb (1 commits) (flutter#18003)
f07712b Roll src/third_party/skia 5f56cb1d3b4f..f5132a05c893 (6 commits) (flutter#17999)
103c9c7 Bumped up the timeout for testAccessibilityFocusOnTextSemanticsProducesCorrectIosViews (flutter#17988)
a1fdff6 Roll src/third_party/skia 81ef385c1fcd..5f56cb1d3b4f (14 commits) (flutter#17991)
22479ca Roll Dart to 726d3c772554924f62db0b9e0d4c280dbbddc824 (flutter#17993)
494a63c Trial PR to enable null safety unfork in the Dart SDK. (flutter#17818)
887efcb Roll fuchsia/sdk/core/linux-amd64 from eapIV... to 3h-X9... (flutter#17987)
50ae2b9 Set SkSL asset manager in RunConfiguration ctor (flutter#17948)
5f437fb Started ignoring remote keyboard notifications. (flutter#17981)
027eff8 Reenable flutter scenic test to identify crashes and follow up on fixes. (flutter#17979)
992a55c Update buildroot (flutter#17978)
d5587df Roll src/third_party/skia 78debd6f6d83..81ef385c1fcd (1 commits) (flutter#17976)
aa00d50 [web] Don't allow empty initial route (flutter#17936)
3b0e415 Roll fuchsia/sdk/core/mac-amd64 from 9O3Ef... to arZdZ... (flutter#17975)
66af9ea Roll src/third_party/skia 981d590e8eba..78debd6f6d83 (5 commits) (flutter#17972)
732bf22 Manual roll of Dart to 03429b20cd67f85d65cc589b529ab8c1a4780912...a53d336b9fd4bbb415d2f1e3f4c653aa107f31c7 (flutter#17971)
cad81c7 Roll src/third_party/skia 1ae3e75a0b4c..981d590e8eba (1 commits) (flutter#17968)
eed05dd Add initial unit tests for the android embedding (flutter#17921)
168a65f Roll src/third_party/dart 2e438d1baffc..a53d336b9fd4 (4 commits) (flutter#17967)
742adb8 Roll src/third_party/skia 97cfb05aabe4..1ae3e75a0b4c (2 commits) (flutter#17966)
805ef7c Roll fuchsia/sdk/core/mac-amd64 from 2CE6x... to 9O3Ef... (flutter#17963)
11c6a18 Roll src/third_party/skia c12aad9485a9..97cfb05aabe4 (3 commits) (flutter#17957)
4e29e57 Roll fuchsia/sdk/core/mac-amd64 from 9-v-E... to 2CE6x... (flutter#17955)
4f3b929 Roll src/third_party/dart 216e3df4526c..2e438d1baffc (7 commits) (flutter#17950)
4f888d6 Change the repo fetch script used in integration tests (flutter#17943)
3999ef9 Roll src/third_party/skia 1e21d14f2b8b..c12aad9485a9 (20 commits) (flutter#17942)
d01de3b Roll src/third_party/dart a69cb6d700f5..216e3df4526c (16 commits) (flutter#17945)
2589d07 Fix accessibility focus loss when first focusing on text field (flutter#17803)
3af2b1a Roll fuchsia/sdk/core/linux-amd64 from _dAFU... to G4HpJ... (flutter#17938)
d132ac5 [web] Fix exception when getting boxes for rich text range (flutter#17933)
cade0e9 [web] Batch systemFontChange messages (flutter#17885)
christopherfujino added a commit that referenced this issue Apr 28, 2020
0c35a34 Roll src/third_party/skia f5132a05c893..4baa7326ccfb (1 commits) (#18003)
f07712b Roll src/third_party/skia 5f56cb1d3b4f..f5132a05c893 (6 commits) (#17999)
103c9c7 Bumped up the timeout for testAccessibilityFocusOnTextSemanticsProducesCorrectIosViews (#17988)
a1fdff6 Roll src/third_party/skia 81ef385c1fcd..5f56cb1d3b4f (14 commits) (#17991)
22479ca Roll Dart to 726d3c772554924f62db0b9e0d4c280dbbddc824 (#17993)
494a63c Trial PR to enable null safety unfork in the Dart SDK. (#17818)
887efcb Roll fuchsia/sdk/core/linux-amd64 from eapIV... to 3h-X9... (#17987)
50ae2b9 Set SkSL asset manager in RunConfiguration ctor (#17948)
5f437fb Started ignoring remote keyboard notifications. (#17981)
027eff8 Reenable flutter scenic test to identify crashes and follow up on fixes. (#17979)
992a55c Update buildroot (#17978)
d5587df Roll src/third_party/skia 78debd6f6d83..81ef385c1fcd (1 commits) (#17976)
aa00d50 [web] Don't allow empty initial route (#17936)
3b0e415 Roll fuchsia/sdk/core/mac-amd64 from 9O3Ef... to arZdZ... (#17975)
66af9ea Roll src/third_party/skia 981d590e8eba..78debd6f6d83 (5 commits) (#17972)
732bf22 Manual roll of Dart to 03429b20cd67f85d65cc589b529ab8c1a4780912...a53d336b9fd4bbb415d2f1e3f4c653aa107f31c7 (#17971)
cad81c7 Roll src/third_party/skia 1ae3e75a0b4c..981d590e8eba (1 commits) (#17968)
eed05dd Add initial unit tests for the android embedding (#17921)
168a65f Roll src/third_party/dart 2e438d1baffc..a53d336b9fd4 (4 commits) (#17967)
742adb8 Roll src/third_party/skia 97cfb05aabe4..1ae3e75a0b4c (2 commits) (#17966)
805ef7c Roll fuchsia/sdk/core/mac-amd64 from 2CE6x... to 9O3Ef... (#17963)
11c6a18 Roll src/third_party/skia c12aad9485a9..97cfb05aabe4 (3 commits) (#17957)
4e29e57 Roll fuchsia/sdk/core/mac-amd64 from 9-v-E... to 2CE6x... (#17955)
4f3b929 Roll src/third_party/dart 216e3df4526c..2e438d1baffc (7 commits) (#17950)
4f888d6 Change the repo fetch script used in integration tests (#17943)
3999ef9 Roll src/third_party/skia 1e21d14f2b8b..c12aad9485a9 (20 commits) (#17942)
d01de3b Roll src/third_party/dart a69cb6d700f5..216e3df4526c (16 commits) (#17945)
2589d07 Fix accessibility focus loss when first focusing on text field (#17803)
3af2b1a Roll fuchsia/sdk/core/linux-amd64 from _dAFU... to G4HpJ... (#17938)
d132ac5 [web] Fix exception when getting boxes for rich text range (#17933)
cade0e9 [web] Batch systemFontChange messages (#17885)
@github-actions
Copy link

github-actions bot commented Sep 3, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants