-
Notifications
You must be signed in to change notification settings - Fork 4
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
Correctness issues #7
Comments
I'm still working on getting the right algorithm, but it's a bit tricky to get something correct while minimizing perf impact. This write up is mostly to quickly document the current problem I am working on. I still plan to write a detailed explanation alongside the algorithm before sending a PR. The basic idea is that in a function coverage from a single script coverage, the ranges form a tree based on the inclusion relation: if a range is included in another one, it's as if this range was a child in a tree.
Now, if you look at ranges for the same function but across different script coverages, the ranges no longer form a tree: they have partial overlap such that no node is the parent of each other.
The root ranges are the same (from
The count of 5 is obtained simply by summing the counts of each root ranges: these are the same. For count of 6, we merge the root range of B with the first part of the child range of A. 9 is found by summing the counts in the intersection of the children. And 8 is found with the root of A and last part of the child range of B. The first version of the algorithm I had was over-splitting the ranges. This is something that is almost fixed but still requires testing. The issue occurs when trying to merge the following range trees:
The expected result is:
But my first version produced:
Chopping down ranges when there is no partial overlap is unsafe because it may break invariants about AST spans, for example by splitting an |
If you support nesting and partial overlap of ranges across coverage from different processes, binary merge (two coverages at a time) is not associative. I have a working binary merge but some issues with n-ary merges. I need to reevaluate what properties apply to coverages. |
Here are the correct merge rules (these rules should restore associativity and match the experimental results): Disjoint:
Nested
Partial overlap
The main thing that bothers me is the left-side bias of partial overlaps. I couldn't find any real-world example where overlap should be resolved with a right-side bias, but I only checked a few examples. If one such example of real-world right-side bias is found, it would mean that it is impossible to write a merge function producing valid results without external input (such as the source code) because of the ambiguity of the overlaps. Here is a small example producing overlapping ranges (that must be resolved with a left-side bias):
By calling it with
But even here, it's not quite clear why the result wouldn't be:
|
This commit uses the [new merge algorithm][merge] to handle sub-processes. It fixes the issues reported in bcoe/v8-coverage-merge#7 and improves performance. merge: https://github.com/demurgos/v8-coverage/blob/master/docs/merge.md
This commit uses the [new merge algorithm][merge] to handle sub-processes. It fixes the issues reported in bcoe/v8-coverage-merge#7 and improves performance. [merge]: https://github.com/demurgos/v8-coverage/blob/master/docs/merge.md
This commit uses the [new merge algorithm][merge] to handle sub-processes. It fixes the issues reported in bcoe/v8-coverage-merge#7 and improves performance. [merge]: https://github.com/demurgos/v8-coverage/blob/master/docs/merge.md
This commit uses the [new merge algorithm][merge] to handle sub-processes. It fixes the issues reported in bcoe/v8-coverage-merge#7 and improves performance. [merge]: https://github.com/demurgos/v8-coverage/blob/master/docs/merge.md Closes bcoe#27
This commit uses the [new merge algorithm][merge] to handle sub-processes. It fixes the issues reported in bcoe/v8-coverage-merge#7 and improves performance. [merge]: https://github.com/demurgos/v8-coverage/blob/master/docs/merge.md Closes bcoe#27
@demurgos perhaps we should just deprecate this repo in favor of |
The lib currently produces incorrect results.
I am still looking into it but here are two examples:
See this gist. Merging
input.json
with itself should simply double the counts. Instead, it returnsoutput.json
.The library uses function names as cache keys, but there are no guarantees about the names: they can be empty strings or duplicated. It causes the lib to try to merge this closure with this one because the coverage gives them both the name
process.on
.The text was updated successfully, but these errors were encountered: