Bug 151116 - Web Inspector: Code coverage profiler: incorrect "in-viewport" detection algorithm
Summary: Web Inspector: Code coverage profiler: incorrect "in-viewport" detection algo...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: Safari 9
Hardware: All All
: P2 Normal
Assignee: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-11-10 12:21 PST by Nikita Vasilyev
Modified: 2015-11-10 13:40 PST (History)
8 users (show)

See Also:


Attachments
Patch (1.87 KB, patch)
2015-11-10 12:39 PST, Nikita Vasilyev
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2015-11-10 12:21:18 PST
The following "is block in the viewport" code is incorrect:

    basicBlocks = basicBlocks.filter(function(block) {
        return (block.startOffset >= startOffset && block.startOffset <= endOffset) || 
               (block.startOffset <= startOffset && block.endOffset >= endOffset);
    });

https://github.com/WebKit/webkit/blob/f70c51a855acc626ec921f7400a69ede4bffac96/Source/WebInspectorUI/UserInterface/Controllers/BasicBlockAnnotator.js#L68-L71

Let's break it down into smaller pieces:

    block.startOffset >= startOffset && block.startOffset <= endOffset

returns true for the following cases (tilt your head 90 degrees):

Viewport: [---]
Block:      [---]


    block.startOffset <= startOffset && block.endOffset >= endOffset

returns true for the following case:

Viewport:  [---]
Block:   [------]


The following case isn't covered, e.g. the filter function wrongly returns false:

Viewport:  [---]
Block:   [---]
Comment 1 Radar WebKit Bug Importer 2015-11-10 12:21:50 PST
<rdar://problem/23485933>
Comment 2 Nikita Vasilyev 2015-11-10 12:31:21 PST
Let's outline all the possible scenarios.

Intersect:
A: [---]
B:   [---]

A: [-----]
B:   [-]

A:   [-]
B: [-----]

A:   [---]
B: [---]


Don't intersect:
A: [---]
B:       [---]

A:       [---]
B: [---]


The easiest way to check if two ranges intersect is to check if they don't intersect. It is also the fastest way.
Comment 3 Nikita Vasilyev 2015-11-10 12:39:26 PST
Created attachment 265220 [details]
Patch
Comment 4 BJ Burg 2015-11-10 12:51:06 PST
Comment on attachment 265220 [details]
Patch

r=me
Comment 5 WebKit Commit Bot 2015-11-10 13:39:58 PST
Comment on attachment 265220 [details]
Patch

Clearing flags on attachment: 265220

Committed r192264: <http://trac.webkit.org/changeset/192264>
Comment 6 WebKit Commit Bot 2015-11-10 13:40:01 PST
All reviewed patches have been landed.  Closing bug.