Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

Cupertino localizations shows up in both the startup CPU and memory profile for customer money. This isn't actually because loading cupertino localizations is that slow, but since cupertino localizations loads first it triggers the parsing of the date symbols table from a const map. Skip this work by instead declaring the date symbols using the intl.DateSymbols class directly.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added a: internationalization Supporting other languages or locales. (aka i18n) c: contributor-productivity Team-specific productivity, code health, technical debt. labels Apr 27, 2022
@jonahwilliams
Copy link
Contributor Author

waiting to see if this triggers a test somewhere...

@jiahaog
Copy link
Member

jiahaog commented Apr 27, 2022

Nice, I was tracking this in b/225289302 too but I'll assign it to you then :)

@jonahwilliams jonahwilliams changed the title [intl] speed up localization generation [intl] speed up localization generation and regenerate symbols Apr 27, 2022
if (writeToFile) {
final File dateLocalizationsFile = File(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'generated_date_localizations.dart'));
dateLocalizationsFile.writeAsStringSync(buffer.toString());
Process.runSync(path.join('bin', 'cache', 'dart-sdk', 'bin', 'dartfmt'), <String>[
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer exists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be missing a test here that should have failed when this was removed?

@jonahwilliams
Copy link
Contributor Author

Would like some guidance on this. There appear to be no tests, but realy this is all an implementation detail anyway. Love to get your thoughts

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems OK to me. Even if the performance difference was a wash, this seems like a better way to deal with the Date symbols..

/// The subset of date symbols supported by the intl package which are also
/// supported by flutter_localizations.''');
buffer.writeln('const Map<String, dynamic> dateSymbols = <String, dynamic> {');
buffer.writeln('final Map<String, intl.DateSymbols> dateSymbols = <String, intl.DateSymbols> {');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final implies lazy initialization like late final?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its lazily initialized, but not in an observable way like late final. I would make these const but intl.DateSymbol cannot be const due to the use of non-final fields

dateLocalizationsFile.writeAsStringSync(buffer.toString());
Process.runSync(path.join('bin', 'cache', 'dart-sdk', 'bin', 'dartfmt'), <String>[
'-w',
final String extension = Platform.isWindows ? '.exe' : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that this has to be done "by hand"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wrote package:process to handle this back in the day

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably, we have tests in place that cover using the dateSymbols? If those are still passing:

LGTM

if (writeToFile) {
final File dateLocalizationsFile = File(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'generated_date_localizations.dart'));
dateLocalizationsFile.writeAsStringSync(buffer.toString());
Process.runSync(path.join('bin', 'cache', 'dart-sdk', 'bin', 'dartfmt'), <String>[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be missing a test here that should have failed when this was removed?

@jonahwilliams
Copy link
Contributor Author

Yeah we don't appear to be running this on CI. Maybe we should, then we could check against a hash or something?

@Hixie
Copy link
Contributor

Hixie commented Apr 27, 2022

test-exempt: code refactor with no semantic change

@fluttergithubbot fluttergithubbot merged commit 29d814b into flutter:master Apr 27, 2022
@jonahwilliams jonahwilliams deleted the faster_localization_init branch April 27, 2022 18:16
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 28, 2022
egramond pushed a commit to egramond/flutter that referenced this pull request May 5, 2022
@jonahwilliams
Copy link
Contributor Author

jonahwilliams commented May 6, 2022

This led to some size reductions on small apps, which is surprising IMO.

@jonahwilliams
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: internationalization Supporting other languages or locales. (aka i18n) c: contributor-productivity Team-specific productivity, code health, technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants