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

Add coverableLineCache param to collect #466

Merged
merged 6 commits into from
Oct 18, 2023
Merged

Add coverableLineCache param to collect #466

merged 6 commits into from
Oct 18, 2023

Conversation

liamappelbe
Copy link
Contributor

coverableLineCache is a map from library URI to the set of all lines that are coverable. If users are doing multiple collect calls over the same set of libraries, they should pass an empty map to this param in the first call, and then pass the same map to all subsequent calls.

If coverableLineCache is provided, we set VmService.getSourceReport's librariesAlreadyCompiled param to all its keys. This disables forced compilation for each of these libraries. The effect of this is that no misses are returned in the response for these libraries (and coverage collection is faster). To fill in the missing misses, we use the values of the coverableLineCache map. Finally, we fill this cache with all the hit and missed lines we've seen for each library.

So coverableLineCache caches all the lines that have been hit or missed in previous collect calls, and uses it to skip recompiling those libraries, and to fill out the misses of subsequent calls.

@liamappelbe liamappelbe changed the title Add coverableLineCache param to collect WIP: Add coverableLineCache param to collect Oct 17, 2023
@liamappelbe liamappelbe changed the title WIP: Add coverableLineCache param to collect Add coverableLineCache param to collect Oct 17, 2023
@liamappelbe liamappelbe marked this pull request as ready for review October 17, 2023 04:15
@coveralls
Copy link

coveralls commented Oct 17, 2023

Coverage Status

coverage: 93.522% (+0.09%) from 93.434% when pulling 0b258e7 on linecache into bcfd888 on master.

Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

Is there any particular reason we're keeping track of the coverable lines for each script instead of just keeping track of which scripts have already been compiled?

lib/src/collect.dart Outdated Show resolved Hide resolved
pubspec.yaml Outdated Show resolved Hide resolved
pubspec.yaml Outdated Show resolved Hide resolved
@liamappelbe
Copy link
Contributor Author

Is there any particular reason we're keeping track of the coverable lines for each script instead of just keeping track of which scripts have already been compiled?

The purpose of force compiling all the libraries is that it tells the VM which lines are coverable, so it can generate a complete list of all the missed lines (particularly for functions that haven't been called). Each collection that the flutter tester does is in a totally fresh VM, so the VM doesn't have any knowledge about which lines are coverable left over from previous collections. So when we set the librariesAlreadyCompiled flag, the libraries that are not force compiled won't have this data, so there will be a bunch of misses that are not included in the source report. To fill in the missing misses, we cache all the coverable lines from previous runs.

@liamappelbe liamappelbe merged commit 908b55d into master Oct 18, 2023
9 checks passed
@liamappelbe liamappelbe deleted the linecache branch October 18, 2023 00:18
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 23, 2023
…age (#136851)

One of the reasons gathering coverage information is expensive is that we have to force compile every function in the libraries we're interested in. Without this, functions that haven't been invoked (so haven't been compiled) won't have any line number information, so the coverage tool doesn't know which lines to add to the list of misses. In flutter's case, the test infra spawns many VMs, and each of these needs to recompile all those libraries.

To fix this, we need a way of skipping force compilation for libraries we've already seen in previous tests, without losing the information about which lines in each library are coverable. So I [added](dart-lang/coverage#466) the `coverableLineCache` to `coverage.collect` in package:coverage v1.7.0. This cache starts out empty, but fills up with lists of all the lines that are coverable for every library as coverage is gathered. package:coverage can then tell the VM not to force compile any libraries in this cache (using `getSourceReport`'s `librariesAlreadyCompiled` param). So the first test suite will still have to compile everything, but subsequent test suites will be much faster.

This speeds up coverage collection significantly, for large test suites:

| Running flutter/packages/flutter tests... | Time | Overhead |
| --- | --- | --- |
| without coverage | 8:53 | - |
| with coverage | 20:25 | 130% |
| with `coverableLineCache` | 12:21 | 40% |

Bug: #100751
auto-submit bot added a commit to flutter/flutter that referenced this pull request Oct 24, 2023
… up coverage" (#137121)

Reverts #136851
Initiated by: CaseyHillers
This change reverts the following previous change:
Original Description:
One of the reasons gathering coverage information is expensive is that we have to force compile every function in the libraries we're interested in. Without this, functions that haven't been invoked (so haven't been compiled) won't have any line number information, so the coverage tool doesn't know which lines to add to the list of misses. In flutter's case, the test infra spawns many VMs, and each of these needs to recompile all those libraries.

To fix this, we need a way of skipping force compilation for libraries we've already seen in previous tests, without losing the information about which lines in each library are coverable. So I [added](dart-lang/coverage#466) the `coverableLineCache` to `coverage.collect` in package:coverage v1.7.0. This cache starts out empty, but fills up with lists of all the lines that are coverable for every library as coverage is gathered. package:coverage can then tell the VM not to force compile any libraries in this cache (using `getSourceReport`'s `librariesAlreadyCompiled` param). So the first test suite will still have to compile everything, but subsequent test suites will be much faster.

This speeds up coverage collection significantly, for large test suites:

| Running flutter/packages/flutter tests... | Time | Overhead |
| --- | --- | --- |
| without coverage | 8:53 | - |
| with coverage | 20:25 | 130% |
| with `coverableLineCache` | 12:21 | 40% |

Bug: #100751
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

Successfully merging this pull request may close these issues.

None yet

3 participants