Luckily, the two cases which were reported could both be remedied by
making more things private.
* `DartFileEditBuilderImpl.librariesToImport` exposed `_LibraryImport`,
but could be made private anyhow. Also, it's package-private code,
so this is not a breaking change.
* `CodegenVisitor.generateConstant` accepted a private type as an
argument, but the whole class can be made private.
Change-Id: I8613812385ed0e9a7e36922d86889dad4cedf3cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428924
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Adding edits (e.g. via `dart fix --apply` are often done with
`List.insert(0, whatnot)` which takes O(n) time.
Here QueueList that can insert fast at both ends is used instead
(and we use `addFirst` instead of `insert(0)`.
On the example from
https://github.com/feinstein/google-i18n-address-dart.git we go from:
```
$ time dart fix --use-aot-snapshot --apply
[...]
249517 fixes made in 255 files.
real 3m55.810s
user 4m1.209s
sys 0m3.714s
(resetting)
$ time dart fix --use-aot-snapshot --apply
[...]
249517 fixes made in 255 files.
real 3m33.966s
user 3m37.588s
sys 0m2.058s
(resetting)
$ time dart fix --use-aot-snapshot --apply
[...]
249517 fixes made in 255 files.
real 3m36.525s
user 3m40.083s
sys 0m1.907s
```
to:
```
$ time dart fix --use-aot-snapshot --apply
[...]
249517 fixes made in 255 files.
real 0m9.970s
user 0m12.676s
sys 0m2.100s
(resetting)
$ time dart fix --use-aot-snapshot --apply
[...]
249517 fixes made in 255 files.
real 0m9.862s
user 0m12.926s
sys 0m1.797s
(resetting)
$ time dart fix --use-aot-snapshot --apply
[...]
249517 fixes made in 255 files.
real 0m9.612s
user 0m12.712s
sys 0m1.834s
```
Statistics on the `real` runtime:
```
N Min Max Median Avg Stddev
x 3 213.966 235.81 216.525 222.10033 11.941664
+ 3 9.612 9.97 9.862 9.8146667 0.18363369
Difference at 95.0% confidence
-212.286 +/- 19.1415
-95.581% +/- 8.61838%
(Student's t, pooled s = 8.44503)
```
For `lsp_many_prefer_single_quotes_violations_benchmark.dart --sizes=3200`:
Before from something like:
```
Initial analysis: 0.115654
First code action call: 0.835152
Subsequent action call 1: 0.538592
Subsequent action call 2: 0.561636
Select all code action call: 1.564402
```
After to something like:
```
Initial analysis: 0.086985
First code action call: 0.411660
Subsequent action call 1: 0.171566
Subsequent action call 2: 0.193708
Select all code action call: 1.107339
```
Statistics on 5 runs gives:
First code action call:
```
Difference at 95.0% confidence
-0.44381 +/- 0.0261597
-52.4602% +/- 3.09218%
(Student's t, pooled s = 0.0179367)
```
Subsequent action call 1:
```
Difference at 95.0% confidence
-0.381012 +/- 0.0195618
-69.9139% +/- 3.5895%
(Student's t, pooled s = 0.0134128)
```
Subsequent action call 2:
```
Difference at 95.0% confidence
-0.360077 +/- 0.0265277
-64.634% +/- 4.76173%
(Student's t, pooled s = 0.0181891)
```
Select all code action call:
```
Difference at 95.0% confidence
-0.405855 +/- 0.027662
-26.7277% +/- 1.82169%
(Student's t, pooled s = 0.0189668)
```
Change-Id: I3868afaa8c32a24c01c3a52bd8a53d5e8e4e3afe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427401
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Copying change builders in order to enable reverting changes from a
single correction producer when there's an exception is expensive.
This CL replaces that implementation with a transactional model.
Clients are not required to start a transaction (that happens
automatically), but are required to signal the end of a transaction by
invoking either `commit` or `revert`. (Actually, `commit` is assumed
if neither method is invoked before computing the `SourceChange`.)
There is some information in the Dart file edit builder related to
imports that isn't correctly handled. The reason for this is that too
much of the import computation is done up-front. I don't think this
will be a problem in practice (or at least not often), but we should
come back at some point to change the implementation so that we retain
abstract data longer and perform more processing at the very end (where
we'll have complete information and probably be able to do a better
job anyway).
This CL improved the performance of the benchmark that adds and applies
fixes for 10,000 lint violations.
Before it took an average of 11216.0 ms.
After it took an average of 4200.2 ms.
Which is about a 62% improvement.
Change-Id: I12710606455a04e34a82308ede5d9fba1c68b972
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428060
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This allows us to traverse the children without needing to create lists.
It also allows us to iterate over lists of nodes more efficiently.
Tested against the script that computes fixes for 10,000 diagnostics,
I'm seeing the following result.
Before this CL the average time was 10692.4 ms.
After this CL the average time was 1900.0 ms.
That's just over an 82% improvement.
Change-Id: Ideff745288c8990e9948b22c5204d176af3cac6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426904
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
I wrote a test that generates 10,000 lines of code, each containing one
violation of `prefer_single_quotes`, computes the fixes for all of the
diagnostics, and applies the 20,000 edits, measuring how long the
application takes.
Before this change the average was 3355.0 ms.
After this change the average is 3.8 ms.
The change was inspired by Jens.
Change-Id: Icd54a81ca3848fd5f0168934f713a7be8caec359
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425601
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This improvement was found by Jens.
The bulk fix processor needs to be able to revert a partial set of edits
that can't be completed because of a conflicting pre-existing edit. In
order to do that efficiently it needs to know whether there are any
edits to be reverted, which it used to do by computing a hash from the
edits both before and after running a correction producer. Computing
the hashes is expensive.
This CL changes the detection to use a modification counter that's
incremented any time new edits are added, removing the computation of
the hash values.
I don't yet have a benchmark for the case that uncovered the issue,
but I do have code that generates a file containing 10,000 violations
of the prefer_single_quotes lint, requests bulk fix results 5 times
to warm up the VM, then requests fixes 5 more times and prints an
average (the times between runs are fairly close, so the standard
deviation is small). The code uses the legacy protocol to request the
fixes, but it doesn't execute any of the code in dartdev.)
Before this change the average was 20670.6 ms.
After this change the average ise 13979.0 ms.
This represents a 32% improvement.
Change-Id: I74c079bef8e095acf4ad36de6d0c0241934f79a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425221
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
* Privatize `DartEditBuilderImpl.dartFileEditBuilder`.
* Rename the `toAdd` parameter on `_addAll` to `items`.
* Remove the unused `required` argument on `_canWriteType`.
* Privatize `DartFileEditBuilderImpl.createEditsForImports`,
`.codeStyleOptions`, and `ensureShown`.
* Remove the unused `useShow` parameter on
`DartFileEditBuilderImpl.importElementLibrary`.
Change-Id: I473788d9d566a2982914c374fce2429909466381
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418703
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
* Uri.isSamePackageAs(Uri) and Uri.isImplementation are each used a
few times. Not as much as I would expect, but this still simplifies
some code.
Change-Id: Ie9020916c793852a0df9d04154420948d942d951
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413801
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Having quick links to pub.dev in pubspec.yaml is a long-standing request, but all of the API options to implemented it seemed bad.
However I was recently made aware that DocumentLinks (which we use for the Flutter example links) support HTTP links and this turns out to be a perfect fit (credit to https://github.com/orestesgaolin for the idea).
Links are built based on the kind of package, so `git` and `hosted` packages will be built accordingly (I special-cased GitHub SSH links but don't know if this could be generalised for other Git-hosting services). We use PUB_HOSTED_URL as the default base for standard Pub packages.
Packages that don't have URLs (such as `path`, `sdk: x` or other unknown kinds) will not produce links.
Fixes https://github.com/Dart-Code/Dart-Code/issues/2785
Change-Id: I1c9e704f67736bbc451866a9e10f7928e2246c7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409660
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
The completion code was no longer using this (we use `ElementLocation2` directly in the completion handler now), and the navigation check was just to ensure we didn't include MultiplyDefinedElements in navigation results.
Change-Id: I8412ec60d3d56386a7ced3d78c3a7428313df5d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402101
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>