• Liam Appelbe's avatar
    Use `coverage.collect`'s `coverableLineCache` param to speed up coverage (#136851) · fb297e1d
    Liam Appelbe authored
    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](https://github.com/dart-lang/coverage/pull/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: https://github.com/flutter/flutter/issues/100751
    fb297e1d
Name
Last commit
Last update
..
bin Loading commit data...
doc Loading commit data...
gradle Loading commit data...
ide_templates/intellij Loading commit data...
lib Loading commit data...
static Loading commit data...
templates Loading commit data...
test Loading commit data...
tool Loading commit data...
README.md Loading commit data...
analysis_options.yaml Loading commit data...
dart_test.yaml Loading commit data...
pubspec.yaml Loading commit data...