Skip to content

[analysis_server] enhance generated code #49229

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

Closed
4 of 5 tasks
asashour opened this issue Jun 10, 2022 · 2 comments
Closed
4 of 5 tasks

[analysis_server] enhance generated code #49229

asashour opened this issue Jun 10, 2022 · 2 comments
Labels
legacy-area-analyzer Use area-devexp instead. P4 type-enhancement A request for a change that isn't a bug

Comments

@asashour
Copy link
Contributor

asashour commented Jun 10, 2022

As hinted in sdk/247557, formatting the generated files takes around 00:01:30.

There seems to be some areas of improvement:

  • use a single function to write the union from all similar places
  • the code of individual field inside canParse can also be unified
current
reporter.push('annotationId');
try {
  if (!obj.containsKey('annotationId')) {
    reporter.reportError('must not be undefined');
    return false;
  }
  final annotationId = obj['annotationId'];
  if (annotationId == null) {
    reporter.reportError('must not be null');
    return false;
  }
  if (annotationId is! String) {
    reporter.reportError('must be of type String');
    return false;
  }
} finally {
  reporter.pop();
}
to be
if (_validateString(obj, reporter, 'annotationId')) {
  return false;
}
  • ? No need for the trailing commas in parameters
  • No need for extra spaces which would be removed by the formatter
  • No need to ''' for string literals
@asashour
Copy link
Contributor Author

asashour commented Jun 10, 2022

This CL changes the time to less than 2 seconds.

https://dart-review.googlesource.com/c/sdk/+/247966

@vsmenon vsmenon added the legacy-area-analyzer Use area-devexp instead. label Jun 10, 2022
copybara-service bot pushed a commit that referenced this issue Jun 12, 2022
Bug: #49229
Change-Id: I6141c48e48fbe88812c10d7fcc3541af28ec36c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247966
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Danny Tuppeny <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
@asashour
Copy link
Contributor Author

This CL uses a single function per type for canParse. The generated code shrinks from 46K to 40K lines.

https://dart-review.googlesource.com/c/sdk/+/248009

@pq pq added P4 type-enhancement A request for a change that isn't a bug analyzer-editing-experience labels Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P4 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants