Bug 161867 - Web Inspector: Use Array.shallowEqual instead of Object.shallowEqual in more places
Summary: Web Inspector: Use Array.shallowEqual instead of Object.shallowEqual in more ...
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: Matt Baker
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-09-12 10:24 PDT by Matt Baker
Modified: 2016-09-13 13:14 PDT (History)
9 users (show)

See Also:


Attachments
[Patch] Proposed Fix (10.51 KB, patch)
2016-09-12 10:28 PDT, Matt Baker
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-yosemite (1.05 MB, application/zip)
2016-09-12 11:25 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews112 for mac-yosemite (1.48 MB, application/zip)
2016-09-12 11:30 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews104 for mac-yosemite-wk2 (886.24 KB, application/zip)
2016-09-12 11:38 PDT, Build Bot
no flags Details
[Patch] Proposed Fix (12.71 KB, patch)
2016-09-12 11:57 PDT, Matt Baker
no flags Details | Formatted Diff | Diff
[Patch] Proposed Fix (13.06 KB, patch)
2016-09-12 13:35 PDT, Matt Baker
no flags Details | Formatted Diff | Diff
[Patch] For Landing (21.26 KB, patch)
2016-09-13 12:41 PDT, Matt Baker
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Baker 2016-09-12 10:24:53 PDT
Summary:
Use Array.shallowEqual instead of Object.shallowEqual in more places. Crude perf testing shows the Array version to be ~30x faster. Array.shallowEqual should also check the type of its arguments before checking for equality. The following currently return true:

Array.shallowEqual(null, null)
Array.shallowEqual("abc", "abc")
Array.shallowEqual(1.23, 1.23)
...
Comment 1 Radar WebKit Bug Importer 2016-09-12 10:25:06 PDT
<rdar://problem/28261328>
Comment 2 Matt Baker 2016-09-12 10:28:20 PDT
Created attachment 288579 [details]
[Patch] Proposed Fix
Comment 3 Build Bot 2016-09-12 11:25:10 PDT
Comment on attachment 288579 [details]
[Patch] Proposed Fix

Attachment 288579 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2060313

New failing tests:
inspector/unit-tests/array-utilities.html
Comment 4 Build Bot 2016-09-12 11:25:13 PDT
Created attachment 288590 [details]
Archive of layout-test-results from ews101 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 5 Build Bot 2016-09-12 11:30:49 PDT
Comment on attachment 288579 [details]
[Patch] Proposed Fix

Attachment 288579 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2060311

New failing tests:
inspector/unit-tests/array-utilities.html
Comment 6 Build Bot 2016-09-12 11:30:53 PDT
Created attachment 288592 [details]
Archive of layout-test-results from ews112 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews112  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 7 Build Bot 2016-09-12 11:38:00 PDT
Comment on attachment 288579 [details]
[Patch] Proposed Fix

Attachment 288579 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2060363

New failing tests:
inspector/unit-tests/array-utilities.html
Comment 8 Build Bot 2016-09-12 11:38:03 PDT
Created attachment 288593 [details]
Archive of layout-test-results from ews104 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 9 Matt Baker 2016-09-12 11:57:35 PDT
Created attachment 288596 [details]
[Patch] Proposed Fix
Comment 10 Devin Rousso 2016-09-12 13:19:12 PDT
Comment on attachment 288596 [details]
[Patch] Proposed Fix

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

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:439
> +        if (!(a instanceof Array) || !(b instanceof Array))

Why not just use Array.isArray()?
Comment 11 Matt Baker 2016-09-12 13:30:47 PDT
(In reply to comment #10)
> Comment on attachment 288596 [details]
> [Patch] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=288596&action=review
> 
> > Source/WebInspectorUI/UserInterface/Base/Utilities.js:439
> > +        if (!(a instanceof Array) || !(b instanceof Array))
> 
> Why not just use Array.isArray()?

`instanceof Array` is far more prevalent in the inspector, but apparently has some shortcomings addressed by `Array.isArray()`: http://web.mit.edu/jwalden/www/isArray.html.

I think it has nicer syntax too. Will change.
Comment 12 Matt Baker 2016-09-12 13:35:16 PDT
Created attachment 288606 [details]
[Patch] Proposed Fix
Comment 13 Joseph Pecoraro 2016-09-13 11:22:14 PDT
Comment on attachment 288606 [details]
[Patch] Proposed Fix

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

r=me

> LayoutTests/inspector/unit-tests/array-utilities.html:102
> +            InspectorTest.expectThat(Array.shallowEqual(new Array(...arr1), new Array(...arr1)), "shallowEqual of equal arrays should be true.");
> +            InspectorTest.expectThat(Array.shallowEqual(new Array(...arr1), arr1), "shallowEqual of equal arrays should be true.");

Would it be clearer writing these as [...arr1]? I don't thin we ever use the Array constructor, and I did a double take.
Comment 14 Matt Baker 2016-09-13 12:00:57 PDT
Comment on attachment 288606 [details]
[Patch] Proposed Fix

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

>> LayoutTests/inspector/unit-tests/array-utilities.html:102
>> +            InspectorTest.expectThat(Array.shallowEqual(new Array(...arr1), arr1), "shallowEqual of equal arrays should be true.");
> 
> Would it be clearer writing these as [...arr1]? I don't thin we ever use the Array constructor, and I did a double take.

I'll remove or rewrite the tests that use the Array constructor.
Comment 15 Matt Baker 2016-09-13 12:33:30 PDT
I'm also going to replace this function used by the Array.prototype.partition test:

let quickEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);

with:

Array.shallowEqual, which is faster.
Comment 16 Matt Baker 2016-09-13 12:41:56 PDT
Created attachment 288718 [details]
[Patch] For Landing
Comment 17 WebKit Commit Bot 2016-09-13 13:14:13 PDT
Comment on attachment 288718 [details]
[Patch] For Landing

Clearing flags on attachment: 288718

Committed r205872: <http://trac.webkit.org/changeset/205872>
Comment 18 WebKit Commit Bot 2016-09-13 13:14:18 PDT
All reviewed patches have been landed.  Closing bug.