Skip to content

perf(xslt): build node-set input without a second parse - #377

Closed
polaz wants to merge 4 commits into
mainfrom
perf/#375-xslt-input-once
Closed

polaz wants to merge 4 commits into
mainfrom
perf/#375-xslt-input-once

Conversation

@polaz

@polaz polaz commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • An XSLT transform over a node-set input builds the engine's source document from the constructs of the implicit C14N 1.0 form, instead of serializing it into a workspace buffer and parsing it back.
  • The tree, line numbers, policy limits and refusals are those of parsing the canonical octets, in the same precedence, and every allocation of the conversion is admitted in the query's storage and the XSLT workspace.

Replaces #376.

Changes

  • c14n::serialize: a monomorphized CanonicalObserver receives start and end tags, text, comments, instructions and the selected axes of omitted elements, borrowing the document; existing callers pass () and write the same octets.
  • xslt::Document::build_with_budget_reported and xslt::DocumentBuilder (public engine API): build a source Document from constructs another reader has read, with the parse's checks, parser-work charges, lexical refusals and element projection for the stated text size.
  • xmldsig::transforms::xslt::source: the canonical walk runs where octet input is decoded, counts the octets, applies the XML input policy limits (size, nodes, depth, namespace bindings) as the preflight would, and records the constructs on a tape in query storage whose growth is admitted against the workspace; after the stylesheet compiles the tape is replayed into the builder.
  • xslt::execute takes the input as octets or a node-set; the separate canonicalization buffer is gone.

Testing

Tests, clippy, formatting, doctests and the xslt feature profile pass locally on macOS with the xmlsec1 oracle; equivalence tests compare the built tree with the parse of the canonical octets over sampled node-sets and at every policy limit.

Closes #375

Summary by CodeRabbit

  • New Features
    • Added a way to build XML documents from structured content while applying parsing limits and validating XML constructs.
    • XSLT transformations can now process node-set inputs without first creating an intermediate canonicalized byte buffer.
    • Added optional observation of canonicalization output, including XML structure and selected attributes and namespaces.
  • Improvements
    • Improved workspace accounting for XSLT inputs and document construction, with clearer enforcement of XML parsing limits.

- C14N reports the structure of its canonical form to a monomorphized
  observer that borrows the document; existing callers pass a no-op
  observer and write the same octets
- a node-set input to the XSLT transform is canonicalized where octet
  input is decoded, before the engine's workspace lease: its octets are
  only counted, the XML input policy limits (size, nodes, depth,
  namespace bindings) apply to the same counts as the preflight of those
  octets, and its constructs are recorded on a tape in query storage
  whose growth is admitted against the XSLT workspace before it
  allocates; text stays borrowed from the document
- after the stylesheet compiles the tape is replayed into the engine's
  new public Document::build_with_budget_reported and DocumentBuilder,
  which apply the checks, parser-work charges and refusals of a parse of
  the canonical text in the same order and receive each run of
  character data whole
- no conversion buffer, decode, lexical preflight or second parse
  remains; equivalence tests compare the built tree with the parse of
  the canonical octets over sampled node-sets and at every policy limit

Closes #375
@coderabbitai

coderabbitai Bot commented Nov 2, 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 41 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 8280184 and 0b5bd28.

Files selected for processing: 2
  • src/xmldsig/transforms/xslt/source.rs
  • src/xmldsig/transforms/xslt/source/tests.rs
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d2a3d5e and 8280184.

Files selected for processing: 11
  • Cargo.toml
  • src/c14n/mod.rs
  • src/c14n/serialize.rs
  • src/xmldsig/transforms.rs
  • src/xmldsig/transforms/xslt.rs
  • src/xmldsig/transforms/xslt/source.rs
  • src/xmldsig/transforms/xslt/source/tests.rs
  • src/xmldsig/transforms/xslt/tests.rs
  • src/xslt/lib.rs
  • src/xslt/model.rs
  • src/xslt/model/builder_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.

Walkthrough

The XSLT adapter now accepts node-set inputs and builds the engine source document from observed canonical structure instead of an intermediate octet buffer. The change adds canonicalization callbacks and a budgeted document builder. Octet input handling remains available through the typed input interface.

Changes: XSLT node-set input

Layer / File(s) Summary
Canonicalization observer
Cargo.toml, src/c14n/*
The serializer reports canonical tags, text, comments, processing instructions, and selected axes of omitted elements to an observer. Existing writer and buffer paths supply a no-op observer. The xslt feature now enables memchr.
Budgeted document builder
src/xslt/lib.rs, src/xslt/model.rs, src/xslt/model/builder_tests.rs
DocumentBuilder accepts XML constructs and builds a document under parse budgets. Shared text handling accounts for text pieces and normalizes line endings across piece boundaries. Tests compare builder results and refusals with parsing.
Canonical tape recording and replay
src/xmldsig/transforms/xslt/source.rs, src/xmldsig/transforms/xslt/source/tests.rs
The source path records canonical events and accounting data in a tape, then replays the constructs through DocumentBuilder. Tests compare built documents, source bytes, line numbers, and refusals with canonicalize-and-parse results, and cover XML policy limits and workspace accounting.
Typed XSLT input integration
src/xmldsig/transforms.rs, src/xmldsig/transforms/xslt.rs, src/xmldsig/transforms/xslt/tests.rs
apply_xslt_transform passes octet or node-set input through the typed interface. Node-set input uses the tape-based source path; octet input retains its storage and optional base URI. Tests cover workspace thresholds and update direct execution calls to use typed octet input.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Transform as XMLDSig XSLT transform
  participant Input as Input::prepare
  participant Recorder as Tape::record
  participant Builder as DocumentBuilder
  participant Engine as XSLT source document
  Transform->>Input: prepare node-set input
  Input->>Recorder: record canonical observer events
  Recorder->>Builder: replay tape constructs
  Builder->>Engine: build source document under budgets
Loading
Merge Risk: Low · previous review 82801

Node-set XSLT inputs that are refused for being too large can report a workspace-limit error instead of the XML document-size error that parsing the same canonical octets gives. This affects only error classification on inputs that are rejected either way. It is a small fix that can be made before or shortly after merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 58.90% 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.
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 "perf(xslt): build node-set input without a second parse" matches the main change. The PR replaces serializing a node-set to bytes and reparsing them with building the XSLT source document d…
Linked Issues check Passed Directly linked issue #375 is the only active target. Its coding requirements are met by the reviewed head, based on the code excerpt and the change summaries.

(1) Tree equals parse of canonical octe…
Out of Scope Changes check Passed Each changed area supports objectives of #375.

- Cargo.toml: adds dep:memchr to the xslt feature. CanonicalCount uses memchr::memchr_iter to count line breaks, so the dependency is required…
Full details: Title check

Explanation

The title "perf(xslt): build node-set input without a second parse" matches the main change. The PR replaces serializing a node-set to bytes and reparsing them with building the XSLT source document directly from the canonical form's reported constructs. The changeset covers the C14N observer, the new XSLT source tape and builder, the removal of the canonicalize_input path, and the related tests, all of which support the title's claim. The title is concise and specific, and it follows a conventional-commit style.

Full details: Linked Issues check

Explanation

Directly linked issue #375 is the only active target. Its coding requirements are met by the reviewed head, based on the code excerpt and the change summaries.

(1) Tree equals parse of canonical octets, with line numbers and source size [#375]: c14n::serialize reports start tags, end tags, text, comments, instructions, and omitted-element axes to CanonicalObserver. source::record consumes these through Recorder. CanonicalCount counts written bytes and \n line breaks, and sets tape.source_bytes. Line numbers come from line_breaks + 1. Document::build_with_budget_reported and DocumentBuilder replay the tape. The tests in source/tests.rs compare the built tree, source bytes, retained bytes, line numbers, and refusals against a parse of the canonical octets, including malformed canonical forms (for example \r in comments and PIs as 
).

(2) XML input policy limits [#375]: Recorder applies the node limit (nodes_limit), depth, and namespace bindings. record applies the document size limit (max_bytes) to the written count. The summary states that tests verify the four limits at each policy value.

(3) Workspace and no conversion buffer [#375]: Tape is held in query storage. Recorder::admit refuses growth beyond limit and reports it as a workspace error. held_bytes includes the tape's retained storage. The canonicalization buffer path (canonicalize_input) is removed from xslt.rs. The node-set test in xslt/tests.rs now expects the same workspace threshold as borrowed canonical octets.

(4) Octet inputs and other C14C callers unchanged [#375]: Input::Octets keeps the existing decode and parse path. Existing C14N callers pass a no-op observer () and write the same octets. The xslt/tests.rs changes wrap octet inputs in Input::Octets and do not change their expected results.

Limits of this assessment: the local test run was not repeated here. I read only part of source.rs (the truncated read ended in Recorder element handling). The build and element-projection logic and the full test bodies rest on the change summaries.

Full details: Out of Scope Changes check

Explanation

Each changed area supports objectives of #375.

  • Cargo.toml: adds dep:memchr to the xslt feature. CanonicalCount uses memchr::memchr_iter to count line breaks, so the dependency is required for the line-number requirement.
  • src/c14n/serialize.rs and src/c14n/mod.rs: add CanonicalObserver, ObservedValue, and the observed writer path. #375 requires the observer. Existing callers use a no-op observer, so their output is unchanged.
  • src/xslt/model.rs and builder_tests.rs: add DocumentBuilder and build_with_budget_reported. #375 names this public API. The text representation change and the split of element projection are refactors that the builder needs to share parser behavior. Builder tests check parity with the parser.
  • src/xslt/lib.rs: re-exports DocumentBuilder. This is the public API that #375 requires.
  • src/xmldsig/transforms.rs and transforms/xslt.rs: route node-set input to the tape path and remove the eager C14N buffer. This is the core of #375.
  • source.rs and its tests: the new tape path and its equivalence tests.
  • xslt/tests.rs: updated call sites and node-set workspace expectations that follow from the new input interface.

No change was found that is unrelated to #375. Refactors and tests support the stated objectives.

Full details: Docstring Coverage

Explanation

Docstring coverage is 58.90% 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 73 functions across 10 files. (1 skipped: 1 unsupported.)

Resolution

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

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-02T19:52:33.418732Z 0b5bd28 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06e9091b23

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/xmldsig/transforms/xslt/source.rs Resolved
Growing a full tape list moves it, so the old allocation and the whole
replacement are live together; admit both before reserving, and check
what the allocator granted afterwards. Regression test: four events fit
a ten-event limit and growing to eight, which peaks at twelve, is
refused.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3558de7a7b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/xslt/model.rs Resolved
The builder assembled an attribute's qualified name by appending, which
could reallocate, before charging the owned bytes; it now charges the
name and value at their exact sizes first and allocates the name with
exactly that capacity. The refusal is the same either way and only the
native peak differs, so no test can observe it without an allocation
counter; the equivalence tests keep the built tree's retained bytes at
or below the parse's.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread src/xmldsig/transforms/xslt/source.rs Resolved
A full tape now ends the recording but not the canonical walk, which
still measures the document and may still fail; the document size and a
canonicalization failure are reported before the tape's workspace, as an
octet input's size precedes its decoding. Regression test: a document
over both the document limit and the tape limit is refused for its size.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b5bd28d3b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/xslt/model.rs Resolved
@polaz

polaz commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Superseded by a squashed branch; a new PR follows.

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): build node-set XSLT input without a second parse

1 participant