Bug 151116

Summary: Web Inspector: Code coverage profiler: incorrect "in-viewport" detection algorithm
Product: WebKit Reporter: Nikita Vasilyev <nvasilyev>
Component: Web InspectorAssignee: Nikita Vasilyev <nvasilyev>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, commit-queue, graouts, joepeck, mattbaker, nvasilyev, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 9   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

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.