Skip to content
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

Formatting generated code is slow #1335

Open
davidmorgan opened this issue Dec 18, 2024 · 0 comments
Open

Formatting generated code is slow #1335

davidmorgan opened this issue Dec 18, 2024 · 0 comments

Comments

@davidmorgan
Copy link
Collaborator

In end_to_end_test:

> dart format --language-version=3.6 lib/values.g.dart
Formatted 1 file (0 changed) in 2.61 seconds.

This is with the current/deprecated "short" formatting style. The new formatter is much faster:

dart format --language-version=3.7 lib/values.g.dart
Formatted lib/values.g.dart
Formatted 1 file (1 changed) in 0.76 seconds.

Note that there is overhead from the command startup, so the speedup is bigger than 3x.

Increasing the line width can help but it's not pretty and the // dart format width=1000000 trick is only possible from 3.7; I'd like to land something that helps existing users.

It looks like it's this clause in the output that causes the problems:

      _$result = _$v ??
          new _$CompoundValueNoNestingField._(
              simpleValue: BuiltValueNullFieldError.checkNotNull(
                  simpleValue, r'CompoundValueNoNestingField', 'simpleValue'),
              validatedValue: validatedValue,
              simpleValueWithNested: simpleValueWithNested.build(),
              validatedValueWithNested: _validatedValueWithNested?.build());

and it can be made fast by adding one trailing comma.

      _$result = _$v ??
          new _$CompoundValueNoNestingField._(
            simpleValue: BuiltValueNullFieldError.checkNotNull(
                simpleValue, r'CompoundValueNoNestingField', 'simpleValue'),
            validatedValue: validatedValue,
            simpleValueWithNested: simpleValueWithNested.build(),
            validatedValueWithNested: _validatedValueWithNested?.build(),
          );

> dart format --language-version=3.6 lib/values.g.dart
Formatted 1 file (0 changed) in 0.72 seconds.

Both versions are fast with "tall" style.

I have a suspicion I'll want to backport this change, so I'll land the absolute minimal fix, i.e. this one comma, first.

A format benchmark also looks like a good thing to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant