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; });
Created attachment 377158 [details] Patch
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?
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. (╯°□°)╯︵ ┻━┻
Created attachment 377374 [details] Patch
Comment on attachment 377374 [details] Patch Nice! r=me
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
Created attachment 377632 [details] Patch I talked with Joe offline, and we both agreed that `pushAll` was a better name :D
Comment on attachment 377632 [details] Patch Clearing flags on attachment: 377632 Committed r249301: <https://trac.webkit.org/changeset/249301>
All reviewed patches have been landed. Closing bug.
<rdar://problem/54861391>