Skip to content

Commit

Permalink
Fix component startup time. (#4137)
Browse files Browse the repository at this point in the history
* Fix component startup time.

The `configureWithApp:` call shouldn't have been added - the
component registration system can provide proper configuration
instead of relying on a static `configureWithApp:` call. Many of
the SDKs relied on singletons being available there, which wasn't
necessary. Instead, this should happen in the component creation
block and use the instantiationTiming parameter on
registerInternalLibrary.

* Fix missing `nil` statement.
  • Loading branch information
ryanwilson committed Nov 28, 2019
1 parent 6f8732d commit 4d35357
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 44 deletions.
11 changes: 2 additions & 9 deletions Firebase/Auth/Source/Auth/FIRAuth.m
Expand Up @@ -1884,19 +1884,12 @@ - (BOOL)getUser:(FIRUser *_Nullable *)outUser
return [[FIRAuth alloc] initWithApp:container.app];
};
FIRComponent *authInterop = [FIRComponent componentWithProtocol:@protocol(FIRAuthInterop)
instantiationTiming:FIRInstantiationTimingAlwaysEager
dependencies:@[]
creationBlock:authCreationBlock];
return @[authInterop];
}

#pragma mark - FIRCoreConfigurable

+ (void)configureWithApp:(nonnull FIRApp *)app {
// TODO: Evaluate what actually needs to be configured here instead of initializing a full
// instance.
// Ensures the @c FIRAuth instance for a given app gets loaded as soon as the app is ready.
[FIRAuth authWithApp:app];
}

#pragma mark - FIRComponentLifecycleMaintainer

- (void)appWillBeDeleted:(nonnull FIRApp *)app {
Expand Down
46 changes: 23 additions & 23 deletions Firebase/DynamicLinks/FIRDynamicLinks.m
Expand Up @@ -129,36 +129,36 @@ + (void)load {
isRequired:NO];
FIRComponentCreationBlock creationBlock =
^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
// Don't return an instance when it's not the default app.
if (!container.app.isDefaultApp) {
// Only configure for the default FIRApp.
FDLLog(FDLLogLevelInfo, FDLLogIdentifierSetupNonDefaultApp,
@"Firebase Dynamic Links only "
"works with the default app.");
return nil;
}
// Ensure it's cached so it returns the same instance every time dynamicLinks is called.
*isCacheable = YES;
id<FIRAnalyticsInterop> analytics = FIR_COMPONENT(FIRAnalyticsInterop, container);
return [[FIRDynamicLinks alloc] initWithAnalytics:analytics];
FIRDynamicLinks *dynamicLinks = [[FIRDynamicLinks alloc] initWithAnalytics:analytics];
[dynamicLinks configureDynamicLinks:container.app];
// Check for pending Dynamic Link automatically if enabled, otherwise we expect the developer to
// call strong match FDL API to retrieve a pending link.
if ([FIRDynamicLinks isAutomaticRetrievalEnabled]) {
[dynamicLinks checkForPendingDynamicLink];
}
return dynamicLinks;
};
FIRComponent *dynamicLinksProvider =
[FIRComponent componentWithProtocol:@protocol(FIRDynamicLinksInstanceProvider)
instantiationTiming:FIRInstantiationTimingLazy
instantiationTiming:FIRInstantiationTimingEagerInDefaultApp
dependencies:@[ analyticsDep ]
creationBlock:creationBlock];
return @[ dynamicLinksProvider ];
}
+ (void)configureWithApp:(FIRApp *)app {
if (!app.isDefaultApp) {
// Only configure for the default FIRApp.
FDLLog(FDLLogLevelInfo, FDLLogIdentifierSetupNonDefaultApp,
@"Firebase Dynamic Links only "
"works with the default app.");
return;
}
[[FIRDynamicLinks dynamicLinks] configureDynamicLinks:app];
// check for pending Dynamic Link automatically if enabled
// otherwise we expect developer to call strong match FDL API to retrieve link
if ([FIRDynamicLinks isAutomaticRetrievalEnabled]) {
[[FIRDynamicLinks dynamicLinks] checkForPendingDynamicLink];
}
}
- (void)configureDynamicLinks:(FIRApp *)app {
FIROptions *options = app.options;
NSError *error;
Expand All @@ -181,11 +181,11 @@ - (void)configureDynamicLinks:(FIRApp *)app {
if (!errorDescription) {
// setup FDL if no error detected
urlScheme = options.deepLinkURLScheme ?: [NSBundle mainBundle].bundleIdentifier;
[[FIRDynamicLinks dynamicLinks] setUpWithLaunchOptions:nil
apiKey:options.APIKey
clientID:options.clientID
urlScheme:urlScheme
userDefaults:nil];
[self setUpWithLaunchOptions:nil
apiKey:options.APIKey
clientID:options.clientID
urlScheme:urlScheme
userDefaults:nil];
} else {
error =
[FIRApp errorForSubspecConfigurationFailureWithDomain:kFirebaseDurableDeepLinkErrorDomain
Expand Down
22 changes: 10 additions & 12 deletions Firebase/Messaging/FIRMessaging.m
Expand Up @@ -225,6 +225,13 @@ + (void)load {
[FIRDependency dependencyWithProtocol:@protocol(FIRAnalyticsInterop) isRequired:NO];
FIRComponentCreationBlock creationBlock =
^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
if (!container.app.isDefaultApp) {
// Only start for the default FIRApp.
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeFIRApp001,
@"Firebase Messaging only works with the default app.");
return nil;
}

// Ensure it's cached so it returns the same instance every time messaging is called.
*isCacheable = YES;
id<FIRAnalyticsInterop> analytics = FIR_COMPONENT(FIRAnalyticsInterop, container);
Expand All @@ -233,28 +240,19 @@ + (void)load {
withInstanceID:[FIRInstanceID instanceID]
withUserDefaults:[GULUserDefaults standardUserDefaults]];
[messaging start];
[messaging configureNotificationSwizzlingIfEnabled];
return messaging;
};
FIRComponent *messagingProvider =
[FIRComponent componentWithProtocol:@protocol(FIRMessagingInstanceProvider)
instantiationTiming:FIRInstantiationTimingLazy
instantiationTiming:FIRInstantiationTimingEagerInDefaultApp
dependencies:@[ analyticsDep ]
creationBlock:creationBlock];

return @[ messagingProvider ];
}

+ (void)configureWithApp:(FIRApp *)app {
if (!app.isDefaultApp) {
// Only configure for the default FIRApp.
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeFIRApp001,
@"Firebase Messaging only works with the default app.");
return;
}
[[FIRMessaging messaging] configureMessaging:app];
}

- (void)configureMessaging:(FIRApp *)app {
- (void)configureNotificationSwizzlingIfEnabled {
// Swizzle remote-notification-related methods (app delegate and UNUserNotificationCenter)
if ([FIRMessagingRemoteNotificationsProxy canSwizzleMethods]) {
NSString *docsURLString = @"https://firebase.google.com/docs/cloud-messaging/ios/client"
Expand Down

0 comments on commit 4d35357

Please sign in to comment.