Conversation
💪 Quality guardian1 tests files modified. You're a champion of test coverage! 🚀 🧹 Tidy commitJust 2 file(s) touched. Thanks for keeping it clean and review-friendly! ✅ New file code coverageNo new file detected so code coverage gate wasn't ran. Client.app: Coverage: 38.39
Generated by 🚫 Danger Swift against ca4b747 |
firefox-ios/Client/TabManagement/TabManagerImplementation.swift
Outdated
Show resolved
Hide resolved
firefox-ios/Client/TabManagement/TabManagerImplementation.swift
Outdated
Show resolved
Hide resolved
firefox-ios/firefox-ios-tests/Tests/ClientTests/TabManagement/TabManagerTests.swift
Outdated
Show resolved
Hide resolved
firefox-ios/firefox-ios-tests/Tests/ClientTests/TabManagement/TabManagerTests.swift
Outdated
Show resolved
Hide resolved
| if let cached = _tabSplitCache { return cached } | ||
| var normalTabs = [Tab]() | ||
| var privateTabs = [Tab]() | ||
| normalTabs.reserveCapacity(tabs.count) |
There was a problem hiding this comment.
Why do we want to reserveCapacity for normal tabs, but not private tabs. Also, the amount of tabs.count isn't directly the capacity we should allocate for normal tabs since it includes private tabs. So I'm just trying to understand the performance gain here, and if this really makes a difference considering this bit of documentation
The Array type’s append(_:) and append(contentsOf:) methods take care of this detail for you, but reserveCapacity(_:) allocates only as much space as you tell it to (padded to a round value), and no more.
There was a problem hiding this comment.
I used reserveCapacity only for normalTabs because normal tabs are usually more numerous than private tabs, and to avoid CoW array reallocation. Even though append is amortized O(1), if the array grows significantly it needs to reallocate multiple times, creating overhead. For example, with 100 normal tabs, appending without a reserved capacity would trigger around 8 reallocations, each an O(n) operation. By using reserveCapacity upfront, space is already allocated and every append is guaranteed O(1). Here's an interesting documentation section: https://developer.apple.com/documentation/swift/array#Growing-the-Size-of-an-Array.
|
First round of review ^^ I still want to make some tests with those changes |
|
Can we do some profiling/bench-marking on the improvement here? I would love to know what kind of speed ups we see with 100 tabs before adding additional complexity to the tab code |
📜 Tickets
Jira ticket
Github issue
💡 Description
normalTabsandprivateTabsare accessed frequently across many classes.normalTabsorprivateTabstriggered a separateO(n)filter. Now both are computed in a singleO(n)pass and cached untiltabschanges.📝 Checklist