dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

It takes too long to create "isolate" #41292

Open govanyjj opened 4 years ago

govanyjj commented 4 years ago

When I execute the following code, I find that waiting for success takes about 1 second or more. Also, when I need to create "isolation" multiple times in my application, I usually wait a long time. When waiting for a long time, I use "CALL STACK" in vscode and use pause> Continue to operate a single "isolate", Then "isolate" will execute correctly and give a return value, otherwise it will wait forever.

int begin = DateTime.now().millisecondsSinceEpoch;
    Isolate isolate = await Isolate.spawn(command.params['method'], argparams,
        debugName: command.params['token'],
        errorsAreFatal: true,
        onError: _onError);
    print(
        "Isolate.spawn ${command.params['token']} complete:cost time:${DateTime.now().millisecondsSinceEpoch - begin}");
I/flutter (29746): Isolate.spawn parsecore complete:cost time:5882
I/flutter (29746): Isolate.spawn hubCore complete:cost time:5911
I/flutter (29746): Isolate.spawn preparse complete:cost time:2071
I/flutter (29746): Isolate.spawn preparse complete:cost time:2549

What can I do to get the return value of "isolate.spwan" quickly?

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.2 19C57, locale zh-Hans-CN)
    • Flutter version 1.12.13+hotfix.8 at /Users/XXXX/development/flutter
    • Framework revision 0b8abb4724 (7 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/XXXX/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.1, Build version 11A1027
    • CocoaPods version 1.9.0

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 43.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.43.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.8.1

[✓] Connected device (2 available)
    • MI PAD 4                     • 69e3c4be      • android-arm64 • Android 8.1.0 (API 27)
    • Android SDK built for x86 64 • emulator-5554 • android-x64   • Android 10 (API 29) (emulator)
mraleph commented 4 years ago

Can you provide a way to reproduce the issue, e.g. the code and step by step guide? It should not take seconds to spawn an isolate.

/cc @mkustermann @aam

govanyjj commented 4 years ago

Can you provide a way to reproduce the issue, e.g. the code and step by step guide? It should not take seconds to spawn an isolate.

* Do you see this sort of delays when you run your application outside of the IDE (e.g. when you just use `flutter run` from command line)

* Do you see this sort of delays in release builds of your application? (`flutter run --release`).

/cc @mkustermann @aam

Hi@mraleph : Thank you for your reply. When I tried to use the two suggestions you gave, currently testing it can give a response within 30 milliseconds quickly, and there is no long-term unresponsive situation under the IDE.

Reproduced in the IDE, as shown in the following code: Github

This is the result of running in vscode

I/flutter (30706): create isolate finish cost time 7801
I/flutter (30706): create isolate finish cost time 7834
I/flutter (30706): create isolate finish cost time 7754
I/flutter (30706): create isolate finish cost time 9757
I/flutter (30706): create isolate finish cost time 9685
I/flutter (30706): create isolate finish cost time 9907
Version: 1.43.2
Commit: 0ba0ca52957102ca3527cf479571617f0de6ed50
Date: 2020-03-24T07:34:57.037Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.2.0

This is the result of running in Android Studio

I/flutter (30843): create isolate finish cost time 3024
I/flutter (30843): create isolate finish cost time 3013
I/flutter (30843): create isolate finish cost time 2962
I/flutter (30843): create isolate finish cost time 3000
I/flutter (30843): create isolate finish cost time 3029
I/flutter (30843): create isolate finish cost time 3020
I/flutter (30843): create isolate finish cost time 3023
I/flutter (30843): create isolate finish cost time 3031
Android Studio 3.6
Build #AI-192.7142.36.36.6200805, built on February 12, 2020
Runtime version: 1.8.0_212-release-1586-b4-5784211 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.2
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 12 
mraleph commented 4 years ago

Sounds like this is caused by IDE debugger being attached.

@rmacnak-google @bkonyi do you maybe recognize the issue?