WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
201082
Web Inspector: replace uses of `Array.prototype.concat` with `Array.prototype.push`
https://bugs.webkit.org/show_bug.cgi?id=201082
Summary
Web Inspector: replace uses of `Array.prototype.concat` with `Array.prototype...
Devin Rousso
Reported
2019-08-23 11:46:38 PDT
function bench(name, f, ...args) { let start = Date.now(); let result = f(...args); let end = Date.now(); let duration = end - start; console.log(name, duration + "ms", result); } bench("push", function() { let last = []; for (let i = 0; i < 1e6; ++i) { last.push(1, 2, 3); } return last; }); bench("concat", function() { let last = []; for (let i = 0; i < 1e6; ++i) { last = last.concat([1, 2, 3]); } return last; }); bench("concat-cache", function() { let last = []; let cache = [1, 2, 3]; for (let i = 0; i < 1e6; ++i) { last = last.concat(cache); } return last; });
Attachments
Patch
(40.45 KB, patch)
2019-08-23 15:03 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Patch
(41.74 KB, patch)
2019-08-27 13:18 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Patch
(41.33 KB, patch)
2019-08-29 15:15 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Devin Rousso
Comment 1
2019-08-23 15:03:59 PDT
Created
attachment 377158
[details]
Patch
Joseph Pecoraro
Comment 2
2019-08-27 12:08:16 PDT
Comment on
attachment 377158
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=377158&action=review
Awesome! Some comments
> Source/WebInspectorUI/ChangeLog:8 > + `x = x.concat(y)` is MUCH slower than `x.push(...y)`.
Maybe we should create: Object.defineProperty(Array.prototype, "pushArray", { value(array) { for (let i = 0, len = array.length; i < len; ++i) this.push(array[i]); } }); Object.defineProperty(Array.prototype, "pushSpread", { value(iterable) { for (let x of iterable) this.push(x); } }); Which seems ~twice as fast as `x.push(...y)` by avoiding unnecessary allocations (and probably GC pressure) and more so if `y` is larger. Names up for grab (pushArray, pushSpread).
> Source/WebInspectorUI/UserInterface/Base/Utilities.js:-693 > -Object.defineProperty(Array.prototype, "keySet",
Removing keySet should be its own patch.
> Source/WebInspectorUI/UserInterface/Views/HeapAllocationsTimelineView.js:220 > - components = components.concat(this._contentViewContainer.currentContentView.selectionPathComponents); > + components.append(...this._contentViewContainer.currentContentView.selectionPathComponents);
Why is this one `append` and not push?
Devin Rousso
Comment 3
2019-08-27 12:12:18 PDT
Comment on
attachment 377158
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=377158&action=review
>> Source/WebInspectorUI/ChangeLog:8 >> + `x = x.concat(y)` is MUCH slower than `x.push(...y)`. > > Maybe we should create: > > Object.defineProperty(Array.prototype, "pushArray", > { > value(array) > { > for (let i = 0, len = array.length; i < len; ++i) > this.push(array[i]); > } > }); > > Object.defineProperty(Array.prototype, "pushSpread", > { > value(iterable) > { > for (let x of iterable) > this.push(x); > } > }); > > Which seems ~twice as fast as `x.push(...y)` by avoiding unnecessary allocations (and probably GC pressure) and more so if `y` is larger. > > Names up for grab (pushArray, pushSpread).
How about `pushIterable` (second implementation)?
>> Source/WebInspectorUI/UserInterface/Views/HeapAllocationsTimelineView.js:220 >> + components.append(...this._contentViewContainer.currentContentView.selectionPathComponents); > > Why is this one `append` and not push?
All the WTF collections use `append`, and I keep mixing them up. (╯°□°)╯︵ ┻━┻
Devin Rousso
Comment 4
2019-08-27 13:18:06 PDT
Created
attachment 377374
[details]
Patch
Joseph Pecoraro
Comment 5
2019-08-29 11:16:13 PDT
Comment on
attachment 377374
[details]
Patch Nice! r=me
WebKit Commit Bot
Comment 6
2019-08-29 13:51:07 PDT
Comment hidden (obsolete)
Comment on
attachment 377374
[details]
Patch Rejecting
attachment 377374
[details]
from commit-queue. Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03', 'apply-attachment', '--no-update', '--non-interactive', 377374, '--port=mac']" exit_code: 2 cwd: /Volumes/Data/EWS/WebKit Logging in as
commit-queue@webkit.org
... Fetching:
https://bugs.webkit.org/attachment.cgi?id=377374&action=edit
Fetching:
https://bugs.webkit.org/show_bug.cgi?id=201082
&ctype=xml&excludefield=attachmentdata Processing 1 patch from 1 bug. Processing patch 377374 from
bug 201082
. Fetching:
https://bugs.webkit.org/attachment.cgi?id=377374
Failed to run "[u'/Volumes/Data/EWS/WebKit/Tools/Scripts/svn-apply', '--force', '--reviewer', u'Joseph Pecoraro']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit Parsed 31 diffs from patch file(s). patching file Source/WebInspectorUI/ChangeLog Hunk #1 succeeded at 1 with fuzz 3. patching file Source/WebInspectorUI/UserInterface/Base/Utilities.js Hunk #1 FAILED at 690. 1 out of 1 hunk FAILED -- saving rejects to file Source/WebInspectorUI/UserInterface/Base/Utilities.js.rej patching file Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js patching file Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js Hunk #1 succeeded at 268 (offset 6 lines). patching file Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js patching file Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js patching file Source/WebInspectorUI/UserInterface/Models/Canvas.js patching file Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js patching file Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js patching file Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js patching file Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js patching file Source/WebInspectorUI/UserInterface/Views/ContentBrowser.js patching file Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js patching file Source/WebInspectorUI/UserInterface/Views/DataGridNode.js patching file Source/WebInspectorUI/UserInterface/Views/HeapAllocationsTimelineView.js patching file Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js patching file Source/WebInspectorUI/UserInterface/Views/NavigationItem.js patching file Source/WebInspectorUI/UserInterface/Views/ObjectTreeView.js patching file Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js patching file Source/WebInspectorUI/UserInterface/Views/OverviewTimelineView.js patching file Source/WebInspectorUI/UserInterface/Views/ResourceCollectionContentView.js patching file Source/WebInspectorUI/UserInterface/Views/ResourceHeadersContentView.js patching file Source/WebInspectorUI/UserInterface/Views/ResourceSecurityContentView.js patching file Source/WebInspectorUI/UserInterface/Views/ScriptClusterTimelineView.js patching file Source/WebInspectorUI/UserInterface/Views/ScrubberNavigationItem.js patching file Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js patching file Source/WebInspectorUI/UserInterface/Views/TreeOutline.js patching file Source/WebInspectorUI/UserInterface/Views/View.js patching file LayoutTests/ChangeLog Hunk #1 succeeded at 1 with fuzz 3. patching file LayoutTests/inspector/unit-tests/array-utilities-expected.txt Hunk #1 FAILED at 132. 1 out of 1 hunk FAILED -- saving rejects to file LayoutTests/inspector/unit-tests/array-utilities-expected.txt.rej patching file LayoutTests/inspector/unit-tests/array-utilities.html Hunk #1 succeeded at 277 with fuzz 2 (offset -27 lines). Failed to run "[u'/Volumes/Data/EWS/WebKit/Tools/Scripts/svn-apply', '--force', '--reviewer', u'Joseph Pecoraro']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit Full output:
https://webkit-queues.webkit.org/results/12981439
Devin Rousso
Comment 7
2019-08-29 15:15:38 PDT
Created
attachment 377632
[details]
Patch I talked with Joe offline, and we both agreed that `pushAll` was a better name :D
WebKit Commit Bot
Comment 8
2019-08-29 16:56:19 PDT
Comment on
attachment 377632
[details]
Patch Clearing flags on attachment: 377632 Committed
r249301
: <
https://trac.webkit.org/changeset/249301
>
WebKit Commit Bot
Comment 9
2019-08-29 16:56:20 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 10
2019-08-29 16:57:18 PDT
<
rdar://problem/54861391
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug