Optimize properties_set to clone once instead of per property#26
Merged
Conversation
When setting multiple properties, the previous implementation cloned the object N times (once per property_set call). Now clones once and sets all properties on the single clone directly. For an object with 9 properties, this roughly halves the cost of properties_set (from ~10us to ~5.5us in php-soap/encoding benchmarks).
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.
Summary
properties_set()previously calledproperty_set()per property, which cloned the object on every call. For an object with N properties, that's N clones and NReflectedClass::fromObject()lookups.Now clones once and sets all properties on the single clone directly using
ReflectionProperty::setValue(). Dynamic properties (stdClass,AllowDynamicProperties) are handled via direct property assignment as a fallback.Impact
For an object with 9 properties,
properties_setcost drops from ~10us to ~5.5us (~45% faster). Measured in the php-soap/encoding benchmark suite where this is on the decode hot path.Changes
ReflectionProperty::setValue()directlyproperty_set)Test plan