Add a few test for the hierarchySort function #22048
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
The
hierarchySort
function is extremely slow. It only contains three statements, but every single one of them are O(n^2) functions.WordPress-iOS/WordPress/Classes/Extensions/Array+Page.swift
Lines 82 to 89 in 6d6f1ca
Test in the app
The issue can be observed on Pages List. Due to an existing bug #21813, Pages List on a site that has lots of pages can't be displayed. If you want to see this issue in a real app, check out this branch, launch the app from Xcode to an iOS device, choose Field Guide (or any site that have 500+ pages), go to pages list, and scroll through the pages.
From my test, the issue is so bad that it's miserable to scroll though Field Guide pages. For a site with 600 pages, scrolling through the list would still gets jerky during fetching the pages.
This PR is not a fix
I'm planning to fix this issue, but this PR is not it. This PR adds some basic unit tests for this function and I'll work on addressing the issue separately.
Regression Notes
N/A