Files
sdk/pkg/analyzer
Jens Johansen 5f23e5b02d [analyzer] Deduplicate simple InterfaceTypeImpl (take 2)
TL;DR: Deduplicate InterfaceTypeImpls and potentially save
hundreds of megabytes of memory.

Note: This is the second attempt where the first attempt
(https://dart-review.googlesource.com/c/sdk/+/321700) was deemed too
complicated.

Most used InterfaceTypeImpl (at least when analyzing `flutter/flutter`)
are simple as in they don't have any type arguments and thus only rely
on the link to the element and the nullability.
In practise we have many such InterfaceTypeImpl duplicated.

This CL deduplicates some of these simple ones.

Analyzing `flutter/flutter` with an empty cache this reduces the heap
usage by about 61MB (more details below).

If issuing enough completion requests a difference of about 327MB is
observed (more details below).

Details (statistics on 2 runs of each):

Starting up from an empty cache:

```
InterfaceTypeImpl (package:analyzer/src/dart/element/type.dart) (instances):
Difference at 95.0% confidence
   -1041287.00 +/- 0.00
   -83.84% +/- 0.00%

ClassElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   3519520.00 +/- 0.00
   6.67% +/- 0.00%

heapUsage:
Difference at 95.0% confidence
   -64279304.00 +/- 1099480.33
   -1.86% +/- 0.03%

InterfaceTypeImpl (package:analyzer/src/dart/element/type.dart) (bytes):
Difference at 95.0% confidence
   -66642368.00 +/- 0.00
   -83.84% +/- 0.00%

heapCapacity:
Difference at 95.0% confidence
   -72339456.00 +/- 44776931.00
   -1.99% +/- 1.23%
```

So ~61 MB less heap usage caused by ~1 million less InterfaceTypeImpl.
It reduces the heap usage from ~3.22GB to ~3.16GB.

After issuing <= 250 completion requests in the "first" 1000 files
(out of 5170 files) (this was done programmatically, but could be done
in a user context):

```
InterfaceTypeImpl (package:analyzer/src/dart/element/type.dart) (instances):
Difference at 95.0% confidence
   -5498798.00 +/- 2065.86
   -84.11% +/- 0.03%

ClassElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   6716416.00 +/- 32304.72
   6.67% +/- 0.03%

heapUsage:
Difference at 95.0% confidence
   -343605032.00 +/- 7789430.55
   -4.16% +/- 0.09%

InterfaceTypeImpl (package:analyzer/src/dart/element/type.dart) (bytes):
Difference at 95.0% confidence
   -351923072.00 +/- 132214.78
   -84.11% +/- 0.03%

currentRSS:
Difference at 95.0% confidence
   -371777536.00 +/- 162914920.52
   -3.80% +/- 1.67%

heapCapacity:
Difference at 95.0% confidence
   -379598848.00 +/- 172922864.48
   -4.18% +/- 1.91%

maxRSS:
Difference at 95.0% confidence
   -558950400.00 +/- 283318881.75
   -5.37% +/- 2.72%
```

So ~327 mb less heap usage caused by almost 5.5 mio less InterfaceTypeImpl.
It reduces the heap usage from ~7.69GB to ~7.37GB.

Change-Id: I2b63dfe3730ba2864f7144b97141cb342e257ba3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326641
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-02 11:21:23 +00:00
..
2023-06-02 18:26:13 +00:00

pub package package publisher

This package provides a library that performs static analysis of Dart code. It is useful for tool integration and embedding.

End-users should use the dart analyze command-line tool to analyze their Dart code.

Integrators that want to add Dart support to their editor should use the Dart Analysis Server. The Analysis Server API Specification is available. If you are adding Dart support to an editor or IDE, please let us know by emailing our list.

Configuring the analyzer

Both dart analyze and Dart Analysis Server can be configured with an analysis_options.yaml file (using an .analysis_options file is deprecated). This YAML file can control which files and paths are analyzed, which lints are applied, and more.

If you are embedding the analyzer library in your project, you are responsible for finding the analysis options file, parsing it, and configuring the analyzer.

The analysis options file should live at the root of your project (for example, next to your pubspec.yaml). Different embedders of analyzer, such as dart analyze or Dart Analysis Server, may choose to find the file in various different ways. Consult their documentation to learn more.

Here is an example file that instructs the analyzer to ignore two files:

analyzer:
  exclude:
    - test/_data/p4/lib/lib1.dart
    - test/_data/p5/p5.dart
    - test/_data/bad*.dart
    - test/_brokendata/**

Note that you can use globs, as defined by the glob package.

Here is an example file that enables two lint rules:

linter:
  rules:
    - camel_case_types
    - empty_constructor_bodies

Check out all the available Dart lint rules.

You can combine the analyzer section and the linter section into a single configuration. Here is an example:

analyzer:
  exclude:
    - test/_data/p4/lib/lib1.dart
linter:
  rules:
    - camel_case_types

For more information, see the docs for customizing static analysis.

Who uses this library?

Many tools embed this library, such as:

Support

Post issues and feature requests at https://github.com/dart-lang/sdk/issues. These will be triaged according to the analyzer triage priorities.

Questions and discussions are welcome at the Dart Analyzer Discussion Group.

Background

The APIs in this package were originally machine generated by a translator and were based on an earlier Java implementation. Several of the API's still look like their Java predecessors rather than clean Dart APIs.

In addition, there is currently no clean distinction between public and internal APIs. We plan to address this issue but doing so will, unfortunately, require a large number of breaking changes. We will try to minimize the pain this causes for our clients, but some pain is inevitable.

License

See the LICENSE file.