Bug 222006 - Web Inspector: Implement Grid Overlay "Show line names" drawing
Summary: Web Inspector: Implement Grid Overlay "Show line names" drawing
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Patrick Angle
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-16 15:33 PST by Patrick Angle
Modified: 2021-02-19 18:20 PST (History)
8 users (show)

See Also:


Attachments
WIP v0.1 - Auto-repeat and implicit names not working (7.60 KB, patch)
2021-02-18 19:08 PST, Patrick Angle
no flags Details | Formatted Diff | Diff
Screenshot of WIP v0.1 (2.44 MB, image/png)
2021-02-18 19:09 PST, Patrick Angle
no flags Details
Patch v1.0 (8.05 KB, patch)
2021-02-19 11:05 PST, Patrick Angle
no flags Details | Formatted Diff | Diff
Screenshot of Patch v1.0 (Explicit and Auto-repeat Line Names) (834.75 KB, image/png)
2021-02-19 11:06 PST, Patrick Angle
no flags Details
Screenshot of Patch v1.0 (Implicit Line Names) (853.02 KB, image/png)
2021-02-19 11:06 PST, Patrick Angle
no flags Details
Screenshot of Patch v1.0 (Line Numbers) (3.29 MB, image/png)
2021-02-19 11:32 PST, Patrick Angle
no flags Details
Screenshot of Patch v1.0 (Line Numbers and Names) (896.56 KB, image/png)
2021-02-19 11:33 PST, Patrick Angle
no flags Details
Patch v1.1 - Review note (8.02 KB, patch)
2021-02-19 11:36 PST, Patrick Angle
no flags Details | Formatted Diff | Diff
Followup (r273155) v1.0 - String performance notes (6.06 KB, patch)
2021-02-19 15:56 PST, Patrick Angle
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Angle 2021-02-16 15:33:14 PST
Add drawing of line names to the grid overlay when enabled.
Comment 1 Radar WebKit Bug Importer 2021-02-16 15:33:36 PST
<rdar://problem/74409722>
Comment 2 Patrick Angle 2021-02-18 19:08:35 PST
Created attachment 420903 [details]
WIP v0.1 - Auto-repeat and implicit names not working
Comment 3 Patrick Angle 2021-02-18 19:09:29 PST
Created attachment 420904 [details]
Screenshot of WIP v0.1
Comment 4 Patrick Angle 2021-02-19 04:23:59 PST
Comment on attachment 420903 [details]
WIP v0.1 - Auto-repeat and implicit names not working

View in context: https://bugs.webkit.org/attachment.cgi?id=420903&action=review

> Source/WebCore/inspector/InspectorOverlay.cpp:1340
> +    auto orderedGridLineNames = direction == GridTrackSizingDirection::ForColumns ? renderStyle->orderedNamedGridColumnLines() : renderStyle->orderedNamedGridRowLines();

A breadcrumb for future me: I think I need to copy these values, not reference them, otherwise I’m actually adding the other grid line name maps to this map.
Comment 5 Patrick Angle 2021-02-19 11:05:25 PST
Created attachment 420990 [details]
Patch v1.0
Comment 6 Patrick Angle 2021-02-19 11:06:21 PST
Created attachment 420991 [details]
Screenshot of Patch v1.0 (Explicit and Auto-repeat Line Names)
Comment 7 Patrick Angle 2021-02-19 11:06:34 PST
Created attachment 420992 [details]
Screenshot of Patch v1.0 (Implicit Line Names)
Comment 8 BJ Burg 2021-02-19 11:26:50 PST
Comment on attachment 420990 [details]
Patch v1.0

View in context: https://bugs.webkit.org/attachment.cgi?id=420990&action=review

r=me

For posterity, please attach a screenshot showing line numbers, and line numbers + labels.

> Source/WebCore/inspector/InspectorOverlay.cpp:1341
> +    auto addOrAppendLineNames = [&](unsigned index, Vector<String> newNames) {

It would be clearer as "appendLineNames" since it always does an append instead of a splice.
Comment 9 Patrick Angle 2021-02-19 11:32:56 PST
Created attachment 420998 [details]
Screenshot of Patch v1.0 (Line Numbers)
Comment 10 Patrick Angle 2021-02-19 11:33:11 PST
Created attachment 420999 [details]
Screenshot of Patch v1.0 (Line Numbers and Names)
Comment 11 Patrick Angle 2021-02-19 11:36:03 PST
Created attachment 421000 [details]
Patch v1.1 - Review note
Comment 12 EWS 2021-02-19 12:01:37 PST
Committed r273155: <https://commits.webkit.org/r273155>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421000 [details].
Comment 13 Darin Adler 2021-02-19 12:09:43 PST
Comment on attachment 421000 [details]
Patch v1.1 - Review note

View in context: https://bugs.webkit.org/attachment.cgi?id=421000&action=review

> Source/WebCore/inspector/InspectorOverlay.cpp:1341
> +    auto appendLineNames = [&](unsigned index, Vector<String> newNames) {

This copies the entire Vector and bumps the reference count on the all the strings. Should take const Vector<String>& instead for better efficiency.

> Source/WebCore/inspector/InspectorOverlay.cpp:1484
> +            lineLabelParts.append(String::number(i + 1));
> +            lineLabelParts.append(String::number(-static_cast<int>(columnPositions.size() - i)));

Using StringBuilder we can build up something like this without allocating and destroying temporary strings. But it might be tricky to refactor to take advantage of that.

> Source/WebCore/inspector/InspectorOverlay.cpp:1494
> +                lineLabel.append(thinSpace);
> +                lineLabel.append(bullet);
> +                lineLabel.append(thinSpace);
> +                lineLabel.append(lineLabelParts[i]);

This is a *very* inefficient way to build up a string. WTF has StringBuilder, which does this kind of thing far more efficiently, and also lets you append more than one thing with a single function call:

    lineLabel.append(thinSpace, bullet, thinSpace, lineLabelParts[I]);

We should probably consider removing the WTF::String::append function because it’s tempting to use it even though it is almost absurdly inefficient.

> Source/WebCore/inspector/InspectorOverlay.cpp:1560
> +        Vector<String> lineLabelParts;
>          if (gridOverlay.config.showLineNumbers) {
> +            lineLabelParts.append(String::number(i + 1));
> +            lineLabelParts.append(String::number(-static_cast<int>(rowPositions.size() - i)));
> +        }
> +        if (gridOverlay.config.showLineNames && rowLineNames.contains(i))
> +            lineLabelParts.appendVector(rowLineNames.get(i));
> +        if (lineLabelParts.size()) {
> +            auto lineLabel = lineLabelParts[0];
> +            for (size_t i = 1; i < lineLabelParts.size(); ++i) {
> +                lineLabel.append(thinSpace);
> +                lineLabel.append(bullet);
> +                lineLabel.append(thinSpace);
> +                lineLabel.append(lineLabelParts[i]);
> +            }

Same comments as above. Also, this code seems repetitive enough that we should find a way to use a helper function instead of use repeating all the code twice.
Comment 14 Patrick Angle 2021-02-19 13:09:22 PST
Comment on attachment 421000 [details]
Patch v1.1 - Review note

View in context: https://bugs.webkit.org/attachment.cgi?id=421000&action=review

>> Source/WebCore/inspector/InspectorOverlay.cpp:1560
>> +            }
> 
> Same comments as above. Also, this code seems repetitive enough that we should find a way to use a helper function instead of use repeating all the code twice.

Working to address these notes today with the exception of spinning the line label drawing code off into a helper; BJ and I discussed this internally and decided we felt it would make the drawing code more complex for only two repetitions.
Comment 15 Patrick Angle 2021-02-19 15:56:51 PST
Reopening to attach new patch.
Comment 16 Patrick Angle 2021-02-19 15:56:52 PST
Created attachment 421050 [details]
Followup (r273155) v1.0 - String performance notes
Comment 17 BJ Burg 2021-02-19 16:05:46 PST
Comment on attachment 421050 [details]
Followup (r273155) v1.0 - String performance notes

r=me
Comment 18 EWS 2021-02-19 16:56:04 PST
Committed r273185: <https://commits.webkit.org/r273185>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421050 [details].
Comment 19 Darin Adler 2021-02-19 18:20:03 PST
Comment on attachment 421000 [details]
Patch v1.1 - Review note

View in context: https://bugs.webkit.org/attachment.cgi?id=421000&action=review

>>> Source/WebCore/inspector/InspectorOverlay.cpp:1560
>>> +            }
>> 
>> Same comments as above. Also, this code seems repetitive enough that we should find a way to use a helper function instead of use repeating all the code twice.
> 
> Working to address these notes today with the exception of spinning the line label drawing code off into a helper; BJ and I discussed this internally and decided we felt it would make the drawing code more complex for only two repetitions.

After you land, I’ll submit a patch that shows you how this can be done in a way that makes the code easier to understand, not more complex. You are welcome to land it like this.