Skip to content

[Feature] iOS: use FlutterEngineGroup for better perf #151

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ios/Classes/FlutterIsolatePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @implementation IsolateHolder

@interface FlutterIsolatePlugin()
@property(nonatomic) NSObject<FlutterPluginRegistrar> * registrar;
@property(nonatomic) FlutterEngineGroup* engineGroup;
@property(nonatomic) FlutterMethodChannel* controlChannel;
@property FlutterEventSink sink;
@end
Expand All @@ -39,6 +40,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterIsolatePlugin *plugin = [[FlutterIsolatePlugin alloc] init];

plugin.registrar = registrar;

plugin.engineGroup = [[FlutterEngineGroup alloc] initWithName:@"flutter_isolate" project:nil];

plugin.controlChannel = [FlutterMethodChannel methodChannelWithName:FLUTTER_ISOLATE_NAMESPACE @"/control"
binaryMessenger:[registrar messenger]];
Expand All @@ -65,20 +68,21 @@ - (void)startNextIsolate {

FlutterCallbackInformation *info = [FlutterCallbackCache lookupCallbackInformation:isolate.entryPoint];

isolate.engine = [FlutterEngine alloc];
isolate.engine = [self.engineGroup makeEngineWithEntrypoint:info.callbackName libraryURI:info.callbackLibraryPath];

if ([isolate.engine respondsToSelector:@selector(initWithName:project:allowHeadlessExecution:)]) {
// use headless execution, if we can
((id(*)(id,SEL,id,id,id))objc_msgSend)(isolate.engine, @selector(initWithName:project:allowHeadlessExecution:) , isolate.isolateId, nil, @(YES));
}
else // older versions before above is available
} else {
// older versions before above is available
[isolate.engine initWithName:isolate.isolateId project:nil];

}

/* not entire sure if a listen on an event channel will be queued
* as we cannot register the event channel until after runWithEntryPoint has been called. If it is not queued
* then this will be a race on the FlutterEventChannels initialization, and could deadlock. */
[isolate.engine runWithEntrypoint:info.callbackName libraryURI:info.callbackLibraryPath];


isolate.controlChannel = [FlutterMethodChannel methodChannelWithName:FLUTTER_ISOLATE_NAMESPACE @"/control"
binaryMessenger:isolate.engine];

Expand Down