Fast path in merge() for single class default#161
Closed
SanderMuller wants to merge 1 commit intolivewire:mainfrom
Closed
Fast path in merge() for single class default#161SanderMuller wants to merge 1 commit intolivewire:mainfrom
merge() for single class default#161SanderMuller wants to merge 1 commit intolivewire:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
/benchmark merge |
Contributor
Benchmark Result: Merge
Median of 10 attempts, 5000 iterations x 10 rounds, 31.98s total To run a specific benchmark, comment |
Contributor
Benchmark Result: Default
Median of 10 attempts, 5000 iterations x 10 rounds, 45.99s total To run a specific benchmark, comment |
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.
The most common usage of
merge()in Blade components is$attributes->merge(['class' => 'some classes']), a single string default for theclasskey. This adds an early return for that exact pattern, bypassing the general-purpose loop that separates appendable/non-appendable attributes, iterates defaults, and callsarray_merge().What changed
A fast path at the top of
BlazeAttributeBag::merge()detects when:classWhen all three hold, it merges the class directly and returns, skipping the escape loop, the appendable/non-appendable separation, and the final
array_merge().Why this works
The general path iterates
$this->attributesto classify each key as appendable or not, runs a second loop to resolve appendable values against defaults (withAppendableAttributeValueinstanceof checks), and finishes witharray_merge(). The fast path skips onee()call, one array copy, one string concatenation.