speeding up iOS plugin initialization #552
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Importing
flutter_tts
can have a small penalty in the performance of the application startup in iOS:during initialisation this plugin is performing some unnecessary operations that could be deferred later in the application lifecycle, when the plugin is actually needed.
The following screenshot is showing the Launches audits for an application I currently have in production. This tool shows that
flutter_tts
is responsible for ~200 ms spent during the app startup, when all the imported plugins are registered via the generatedregisterWithRegistry(:)
method. This procedure is executed on the main thread within theAppDelegate.application(:didFinishLaunchingWithOptions:)
method.flutter_tts
is spending some time in this phase eagerly initialising thelanguage
andlanguages
fields:Both these fields could be initialised lazily (just as the
audioSession
shared instance is already being initialised lazily), since they are not needed until later, when the plugin is eventually used by the application.This PR aims at solving this small but noticeable performance impact of
flutter_tts
in iOS by simply initialising thelanguage
andlanguages
fields lazily: