perf(autoloader): optimize package list accumulation in loop#10341
Open
gr8man wants to merge 1 commit into
Open
perf(autoloader): optimize package list accumulation in loop#10341gr8man wants to merge 1 commit into
gr8man wants to merge 1 commit into
Conversation
Contributor
|
Thanks for the PR. I have to say I respect the ambition here. Not every The implementation itself looks fine to me, but I think the performance framing is doing more work than the code change needs. I'd trim the PR body quite a bit and frame this as a small internal cleanup. I'd also consider dropping the new test. It reads a bit like |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
In
Autoloader::loadComposerNamespaces(),array_merge()was being used inside aforeachloop to accumulate composer packages into$packageList:Complexity Analysis:
Before ($i$ , $i \times S$ , where $S$ is the size of each package version list) plus the new ones.
array_mergeinside the loop):On each iteration
array_mergeallocates a completely new array and copies all existing elements from$packageList(which has sizeAfter (Nested
foreachloop with direct assignment):The nested loop directly assigns elements to
$packageListone by one. This preserves the exact behavior ofarray_merge()where duplicate string keys (package names) in subsequent array elements overwrite previous ones, while completely avoiding intermediate array copying.This PR shifts the package list building process from quadratic time$O(N^2)$ to linear time $O(N)$ while maintaining 100% behavioral compatibility with the original
array_mergelogic.Additionally, a unit test was added to verify the package list auto-discovery flow inside
loadComposerNamespaces.Checklist: