Skip to content

perf(xslt): project only changed bindings and uninterned values into SXD - #380

Merged
polaz merged 1 commit into
mainfrom
perf/#379-sxd-projection
Nov 3, 2026
Merged

polaz merged 1 commit into
mainfrom
perf/#379-sxd-projection

Conversation

@polaz

@polaz polaz commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The XPath projection into SXD carries only the namespace bindings each element changes relative to its parent, and stores text-like values without the keyed string pool.
  • XSLT 16384 verify: the projection falls from 13.1% to 6.1% of the command; user CPU 64.8 -> 60.6 ms.

Changes

  • Elements are projected with their changed bindings only; a binding list that does not line up with its parent's is still projected whole. Every SXD reader of bindings walks the ancestors with shadowing, so namespace axis, prefix and default-namespace lookups see the same in-scope lists.
  • Attribute values, text, comments and instruction values bypass the string pool; names stay interned.
  • Node arenas and per-element attribute and child lists are reserved from the counts the storage charge already computes (Package::with_requirements, Element::reserve).
  • prefix_for_namespace_uri skips a prefix a nearer element rebinds, in both SXD backends.

Testing

Tests, lints and formatting pass on macOS; CI runs the full platform and feature matrix. A regression test covers the rebound-prefix lookup, and projection tests check that every projected element sees its source element's in-scope bindings.

Closes #379

Summary by CodeRabbit

  • New Features
    • Added options to preallocate storage when creating a document package and to reserve space for an element’s attributes and children.
  • Bug Fixes
    • Improved namespace handling so that a child element’s namespace binding correctly takes precedence over a conflicting binding inherited from its parent.
    • XPath document projections now preserve in-scope namespace bindings, including inherited, rebound, and default namespaces.

@coderabbitai

coderabbitai Bot commented Nov 3, 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 59 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
Commits

Reviewing files that changed from the base of the PR and between 2f3fa92 and d30f44e.

Files selected for processing: 9
  • src/sxd_document/dom.rs
  • src/sxd_document/dom_no_unsafe.rs
  • src/sxd_document/dom_no_unsafe/namespace_tests.rs
  • src/sxd_document/lib.rs
  • src/sxd_document/raw.rs
  • src/sxd_document/raw_no_unsafe.rs
  • src/sxd_document/storage.rs
  • src/xslt/xpath.rs
  • src/xslt/xpath/namespace_projection_tests.rs

No actionable comments were generated in the recent review.

Walkthrough

The change adds storage capacity APIs, updates namespace-prefix lookup to skip shadowed prefixes, and changes XPath semantic projection to use storage requirements, project changed namespace bindings, and store selected values without the shared string pool.

Changes: SXD Storage and XPath Projection

Layer / File(s) Summary
Storage capacity APIs
src/sxd_document/storage.rs, src/sxd_document/raw.rs, src/sxd_document/raw_no_unsafe.rs, src/sxd_document/lib.rs, src/sxd_document/dom.rs, src/sxd_document/dom_no_unsafe.rs
Values<T> can create native storage with capacity and reserve additional capacity. Storage and Package accept storage requirements. Both Element implementations expose reserve for attributes and children.
Namespace-prefix lookup
src/sxd_document/raw.rs, src/sxd_document/raw_no_unsafe.rs, src/sxd_document/dom_no_unsafe.rs, src/sxd_document/dom_no_unsafe/namespace_tests.rs
Namespace-prefix lookup skips bindings shadowed by nearer elements. Tests cover a child rebinding and lookups on the child and parent.
Semantic document projection
src/xslt/xpath.rs, src/xslt/xpath/namespace_projection_tests.rs, src/sxd_document/raw_no_unsafe.rs
XPath projection estimates storage requirements and constructs a package with those capacities. It reserves element attribute and child capacity, projects changed namespace bindings, and stores attribute values, text, comments, and processing-instruction values without the shared string pool. Tests cover namespace projection and binding changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Projection as project_semantic_document
  participant Requirements as semantic_projection_requirements
  participant Package as Package::with_requirements
  participant Storage as Storage::with_requirements
  participant Element as project_element
  Projection->>Requirements: Compute StorageRequirements
  Projection->>Package: Create package with requirements
  Package->>Storage: Initialize node arenas with capacities
  Projection->>Element: Project elements and reserve attribute and child capacity
Loading
Merge Risk: Minimal · previous review 2f3fa

No identified issue remains that should block merging after normal checks.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check Inconclusive Directly linked issue #379 has four coding objectives. Status per objective:

1. Project only changed namespace bindings, with fallback to the full list when lists do not line up. Implemented. `change…
Confirm which Storage backend (src/sxd_document/raw.rs or raw_no_unsafe.rs) the XSLT projection uses under the default and CI feature sets. If raw.rs is an active backend, confirm whether its attribute, text, comment, and instruction value …
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: projecting only changed namespace bindings and storing uninterned values into SXD. The changeset matches both. The title uses a conventional commit prefix (perf) …
Out of Scope Changes check Passed Every changed file supports an objective of #379 or its acceptance criteria.

- src/xslt/xpath.rs: changed-binding projection, value and name handling in the projection path, and storage requirements …
Full details: Title check

Explanation

The title names the two main changes: projecting only changed namespace bindings and storing uninterned values into SXD. The changeset matches both. The title uses a conventional commit prefix (perf) and a scope (xslt), and it is specific enough for a teammate scanning history. It does not mention the arena reservation or the shadowed-prefix fix, which is expected for a title of this length.

Full details: Out of Scope Changes check

Explanation

Every changed file supports an objective of #379 or its acceptance criteria.

  • src/xslt/xpath.rs: changed-binding projection, value and name handling in the projection path, and storage requirements computed before Package::with_requirements. Supports objectives 1 and 4.
  • src/sxd_document/raw.rs and raw_no_unsafe.rs: shadowed-prefix lookup fix (objective 3). raw_no_unsafe.rs also carries the value bypass (objective 2).
  • src/sxd_document/raw.rs, raw_no_unsafe.rs, dom.rs, dom_no_unsafe.rs, lib.rs, storage.rs: with_requirements, element_reserve, and Values::with_capacity and reserve_exact. These pre-size arenas and child lists from the counts that the storage charge already computes. The change supports the projection cost goal of #379 and the storage admission bound. The issue does not name pre-reservation directly, but it is part of the same projection path and is disclosed in the PR description.
  • Tests (namespace_projection_tests.rs, dom_no_unsafe/namespace_tests.rs): cover objectives 1 and 3.

No changed file lacks a connection to #379.

Full details: Docstring Coverage

Explanation

Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 9 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Linked Issues check

Explanation

Directly linked issue #379 has four coding objectives. Status per objective:

  1. Project only changed namespace bindings, with fallback to the full list when lists do not line up. Implemented. changed_bindings in src/xslt/xpath.rs compares each child list with its parent by prefix and URI. It projects the full list when the prefixes do not align. namespace_projection_tests.rs covers identical, extended, reordered, and parentless lists, and checks in-scope bindings for each projected element.

  2. Store attribute values, text, comments, and instruction values without the keyed string pool. Names stay interned. Implemented only in src/sxd_document/raw_no_unsafe.rs, which now uses InternedString::from_str for these values. The diff of src/sxd_document/raw.rs shows no change to value storage. Its value setters therefore still appear to use the pool, unless they already bypass it. Whether raw.rs is the backend used by the XSLT projection cannot be established from the evidence read. The Cargo.toml feature definitions were truncated and could not be read.

  3. prefix_for_namespace_uri must not report a prefix shadowed by a nearer element. Implemented in both src/sxd_document/raw.rs and src/sxd_document/raw_no_unsafe.rs. The regression test in src/sxd_document/dom_no_unsafe/namespace_tests.rs covers the no_unsafe backend only.

  4. Storage admission must still bound allocations. Satisfied by the diff. semantic_projection_requirements feeds sxd_document_no_unsafe::estimated_storage_bytes, which is charged to the meter before Package::with_requirements allocates the arenas.

The acceptance criterion requiring unchanged results on the XSLT donor and engine suites is not reported in the PR, and the diff cannot show it. The PR reports before-and-after timings. Timings are not coding requirements.

Resolution

Confirm which Storage backend (src/sxd_document/raw.rs or raw_no_unsafe.rs) the XSLT projection uses under the default and CI feature sets. If raw.rs is an active backend, confirm whether its attribute, text, comment, and instruction value paths still use the keyed string pool. Provide the donor and engine suite results that the acceptance criteria require.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between db90482 and 2f3fa92.

Files selected for processing: 9
  • src/sxd_document/dom.rs
  • src/sxd_document/dom_no_unsafe.rs
  • src/sxd_document/dom_no_unsafe/namespace_tests.rs
  • src/sxd_document/lib.rs
  • src/sxd_document/raw.rs
  • src/sxd_document/raw_no_unsafe.rs
  • src/sxd_document/storage.rs
  • src/xslt/xpath.rs
  • src/xslt/xpath/namespace_projection_tests.rs

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T17:39:39.802316Z d30f44e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

- an element projected for XPath carries only the namespace bindings it
  changes relative to its parent; every SXD reader of bindings walks the
  ancestors with shadowing, so the namespace axis, prefix and default
  namespace lookups resolve the same in-scope lists, and a list that does
  not line up with its parent's is still projected whole
- attribute values, text, comments and instruction values are stored
  without the keyed string pool; names keep their interning
- the projection reserves its node arenas and each element's attribute
  and child lists from the counts its storage charge already uses
- prefix_for_namespace_uri skips a prefix a nearer element rebinds, in
  both SXD backends, so a shadowed prefix is never reported for a URI

Regression test: a_prefix_rebound_by_a_nearer_element_is_not_reported_
for_its_outer_uri. Projection tests check every projected element sees
its source element's in-scope bindings and that only line-up lists are
reduced. XSLT 16384 verify: projection 13.1% -> 6.1% of the command,
user CPU 64.8 -> 60.6 ms, minimum 73.4 -> 69.7 ms.

Closes #379
@polaz
polaz force-pushed the perf/#379-sxd-projection branch from 2f3fa92 to d30f44e Compare November 3, 2026 17:37
@polaz
polaz merged commit efca82a into main Nov 3, 2026
53 of 55 checks passed
@polaz
polaz deleted the perf/#379-sxd-projection branch November 3, 2026 20:10
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.

perf(xslt): project only changed namespace bindings and uninterned values into SXD

1 participant