Cache xsi:type encoder detection in XsiTypeDetector#56
Merged
veewee merged 3 commits intophp-soap:mainfrom Mar 26, 2026
Merged
Conversation
Introduces ScopedCache: a generic, GC-safe WeakMap-based cache scoped to an object's lifetime. Used by XsiTypeDetector and EncoderDetector. XsiTypeDetector now caches the full FixedIsoEncoder per (registry, namespace, typeName, meta fingerprint). The meta fingerprint includes isElement, isAttribute, isNullable, isList, and isQualified. This eliminates both encoder detection and iso rebuilding on the decode hot path for repeated xsi:type values. EncoderDetector refactored to use ScopedCache (replaces inline WeakMap). ~34% improvement on encoded decode path.
7 tasks
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
Introduces
ScopedCache(src/Cache/ScopedCache.php): a generic, GC-safe WeakMap-based cache scoped to an object's lifetime. When the scope object is garbage collected, all its cached entries are released. Marked@internal.XsiTypeDetector: caches the full
FixedIsoEncoderper(registry, namespace, typeName, meta fingerprint). The meta fingerprint includesisElement,isAttribute,isNullable,isList, andisQualified. This eliminates both encoder detection and iso rebuilding on the decode hot path for repeated xsi:type values.EncoderDetector: refactored from inline
WeakMapto useScopedCache(same behavior, consistent pattern).Cache key design
The cache key is
namespace|typeNameplus a meta fingerprint of 5 bits that affect the encoder'siso()behavior. These were identified by tracing every$meta->access in encoderiso()methods:isElement/isAttribute: read byErrorHandlingEncoder::iso()isNullable: read byObjectAccess,AnyElementEncoder::iso()isList: read byObjectEncoder::from(),AnyElementEncoder::iso()isQualified: read byElementBuilder(encode path, captured in iso closures)Other XsdType properties (targetNodeName, targetNamespace) vary per property but only affect the encode direction. Since the cached
FixedIsoEncoderis only used for decode (fromXsiTypeEncoder::from()), they don't need to be in the key.Impact
~34% improvement on encoded decode path (113ms to 75ms for 500 items). Literal decode and all encode paths are unaffected.
Test plan