Skip to content

Skip xsi:type detection for elements without attributes - #81

Merged
veewee merged 3 commits into
php-soap:mainfrom
veewee:perf-skip-xsi-detection-without-attributes
Oct 16, 2026
Merged

veewee merged 3 commits into
php-soap:mainfrom
veewee:perf-skip-xsi-detection-without-attributes

Conversation

@veewee

@veewee veewee commented Oct 15, 2026 •

Copy link
Copy Markdown
Member
Q A
Type improvement
BC Break no
Fixed issues

Summary

On decode, XsiTypeEncoder asks XsiTypeDetector for an xsi:type on every element it sees. Most elements in a literal response carry no attributes at all, yet each one still pays for two attribute lookups and the Option wrapping around them. I now check hasAttributes() first and go straight to the inner encoder when it is false.

The detector only reads the xsi:type attribute of the element itself. It does not look at parents, children or the context type, so an element without attributes always ended up on the inner encoder before this change too. Dom\Element counts namespace declarations as attributes, which means an element that only declares xmlns:... still goes through the detector as before. The DisregardXsiInformation arm still runs first, so encoders that ignore xsi information do not get an extra parse.

3MB synthetic workloads, seconds, median of 3 interleaved rounds:

workload main this PR
decode dense, stdClass 0.282 0.220 (-22%)
decode dense, classmap 0.348 0.282 (-19%)
decode sparse, stdClass 0.490 0.453 (-8%)
decode sparse, classmap 0.930 0.887 (-5%)
encode dense, stdClass 0.716 0.737 (+3%)
encode dense, classmap 0.771 0.755 (-2%)
encode sparse, stdClass 1.451 1.453 (0%)
encode sparse, classmap 1.581 1.615 (+2%)

Encode does not pass through this code, so those rows show the noise level of the runs. In phpbench, literal decode is 9% to 12% faster and literal sparse decode 3% to 5%. Encoded decode stays flat because every element there carries an xsi:type. The other subjects move between -4% and +4%, which matches how much the ext-soap subjects move without any change.

Summary by CodeRabbit

  • Bug Fixes
    • XML elements without attributes and without xsi:type are now decoded by the underlying encoder, preserving the expected value type.

An xsi:type can only live on the element itself, so an element without
attributes always decodes through the inner encoder. Checking
hasAttributes() first avoids the two attribute lookups and the Option
wrapping for every such element on decode.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b0051b09-8c70-467f-823b-a3b9fb0a3377
📥 Commits

Reviewing files that changed from the base of the PR and between b94731a and 0569f1f.

📒 Files selected for processing: 2
  • src/Encoder/XsiTypeEncoder.php
  • tests/Unit/Encoder/XsiTypeEncoderTest.php

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eefa4b0a-eb9e-4ae0-a673-08cc857f8582
📥 Commits

Reviewing files that changed from the base of the PR and between 403a479 and b94731a.

📒 Files selected for processing: 2
  • src/Encoder/XsiTypeEncoder.php
  • tests/Unit/Encoder/XsiTypeEncoderTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

XsiTypeEncoder::from now uses the inner encoder when an element has no attributes. Tests cover this fallback, fallback with an unrelated namespace attribute, and decoding through a detected xsi:type.

Changes: XSI type decoding

Layer / File(s) Summary
Decoder fallback and tests
src/Encoder/XsiTypeEncoder.php, tests/Unit/Encoder/XsiTypeEncoderTest.php
from skips xsi:type detection when the element has no attributes and uses the inner encoder. Tests cover detected xsd:int, elements without attributes, and elements with an unrelated namespace attribute.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to b9473

No merge-blocking issue is identified; the change is ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: skipping xsi:type detection when elements have no attributes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@veewee

veewee commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…tion-without-attributes

# Conflicts:
#	src/Encoder/XsiTypeEncoder.php
#	tests/Unit/Encoder/XsiTypeEncoderTest.php
@veewee
veewee merged commit 19636b1 into php-soap:main Oct 16, 2026
13 checks passed
@veewee
veewee deleted the perf-skip-xsi-detection-without-attributes branch October 16, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant