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

Wire up custom event loop interop #175

Closed
pchampio opened this issue Jun 30, 2019 · 3 comments · Fixed by #219
Closed

Wire up custom event loop interop #175

pchampio opened this issue Jun 30, 2019 · 3 comments · Fixed by #219
Labels
embedder Issue concerns the embedder package engine Depends on support form the Flutter Engine enhancement New feature or request GLFW

Comments

@pchampio
Copy link
Member

The flutter/engine GLFW implementation makes use of the custom_task_runners.
The implementation is available here: flutter/engine@4e344e6 , it is just a matter of porting it to go-flutter.

The use of a custom event loop interop will resolve some delay experienced by plugin author #132 (comment) , and it will able us to have 'true' passive sleep. (instead of fetching platform message every 0.016 seconds even when there is no message available)

@davidmartos96
Copy link
Contributor

davidmartos96 commented Jun 30, 2019

@davidmartos96 question:
I was comparing the performance of the sqlite library on the android emulator vs go-flutter. It looks like the encoding and decoding performance of the platform calls is much worse in go-flutter.

1 INSERT (time since the call to invokeMethod in Dart until the reply is received in Dart)
Android emulator -> 1 ms
Go Flutter -> 30 ms

Quite different performance right?

The time it takes to make the actual INSERT measured in the native side is 100 us in both platforms.

Is this a known limitation of the project? Awesome project BTW :)

@Drakirus response:
@davidmartos96 thanks for the feedback.
The encoding and decoding performance should be as good as on Android, Golang is Fast.

I'm pretty sure the 30ms comes from the MainLoop.

The flutter engine team added FlutterEngineFlushPendingTasksNow as a workaround for embedders to flush tasks (platform messages) on threads where the engine didn't own the message loop (or couldn't interact with the same as is the case on Android and iOS).

On go-flutter, we could use PollEvents to have an instant feedback platform messages, but that would result in high CPU load.
In order to reduce CPU load we choose to wait 16ms in order to get the 60fps-ish iterations while having the possibility to fetch platforms messages when no pending frames are to be swapped.
I assume the 30ms delay you are experiencing comes from 2 loop cycles, one to get the platform message and issuing the task into a specific goroutine; and one to send back the message to Dart.

Can you rerun your test by using a custom MainLoop (repalce WaitEventsTimeout by PollEvents) ?

Using PollEvents did the trick. Thanks for the information! Not quite a problem for the sqlite plugin at least, because it provides a way to execute operations in batches, without going back and forth from Dart and native. Useful to know none the less.

@pchampio pchampio added embedder Issue concerns the embedder package enhancement New feature or request GLFW engine Depends on support form the Flutter Engine labels Jul 1, 2019
@pchampio
Copy link
Member Author

pchampio commented Aug 1, 2019

Try it out with hover run -b "@beta"

@pchampio pchampio mentioned this issue Aug 2, 2019
@pchampio
Copy link
Member Author

pchampio commented Sep 3, 2019

fix taged in tag: v0.29.0.

The delay of 30ms still occurs, there is currently no solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedder Issue concerns the embedder package engine Depends on support form the Flutter Engine enhancement New feature or request GLFW
Development

Successfully merging a pull request may close this issue.

2 participants