Skip to content

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

Merged
polaz merged 6 commits into
mainfrom
perf/#375-xslt-input-once
Nov 3, 2026
Merged

polaz merged 6 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, names and values included, is admitted in the query's storage and the XSLT workspace before it is made.
  • Linux builds link with mold instead of the self-contained rust-lld.

Replaces #377.

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.
  • CI: the shared build-cache action installs mold on Linux runners and selects it through RUSTFLAGS; the alloc-only job, which also checks thumbv7em and wasm32, keeps the default linker. The benchmark image links with mold per target.

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. The full workspace builds and links with mold on Linux, and its test results match the default linker's.

Closes #375

Summary by CodeRabbit

  • New Features
    • Added a public, budget-aware XML document builder for constructing documents from elements, attributes, text, comments, and processing instructions.
    • Added canonicalization callbacks that report emitted XML structure and values.
  • Improvements
    • XSLT transforms can process XML node-set inputs directly, reducing workspace needed for conversion.
    • XML construction and parsing apply consistent limits and validation, including for text supplied in multiple pieces.
    • XSLT document construction now accounts for parse and workspace budgets.

polaz added 3 commits November 2, 2026 22:42
- 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, including the reallocation peak, is admitted against the
  XSLT workspace before it allocates; text stays borrowed from the
  document, and refusals keep the precedence of octet input
- 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, lexical refusals and
  element projection of a parse of the canonical text in the same order,
  admit every name and value before copying it, 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
The shared build-cache action installs mold on Linux runners and appends
-C linker-features=-lld -C link-arg=-fuse-ld=mold to RUSTFLAGS before the
cache step, so cached artifacts match the flags they were built with.
mold links with fewer threads and less random I/O than the self-contained
rust-lld. macOS and Windows jobs keep their linkers.

The alloc-only job turns it off: it also checks thumbv7em and wasm32,
where rustc does not accept -C linker-features on stable.
The benchmark image installs mold and selects it per target: x86_64
turns off the self-contained rust-lld first, other targets replace the
system linker. The flags are per-target so the alloc-free cross targets
are untouched, and a RUSTFLAGS given to the container still wins.
@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 17 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 9cb8603 and 2999adc.

Files selected for processing: 2
  • src/xslt/model.rs
  • src/xslt/model/builder_tests.rs

No actionable comments were generated in the recent review.

Walkthrough

The XSLT transform now builds source documents directly from node-set inputs using canonicalization callbacks and a budgeted document builder. The change also adds mold linker configuration to the Rust build-cache action and benchmark image.

Changes: XSLT node-set source construction

Layer / File(s) Summary
Budgeted semantic document builder
Cargo.toml, src/xslt/lib.rs, src/xslt/model.rs, src/xslt/model/builder_tests.rs
A public builder constructs documents from semantic XML constructs with validation and parse-budget checks. Text-piece handling supports CRLF across piece boundaries. Tests compare builder behavior with parsing.
Canonicalization observer callbacks
src/c14n/mod.rs, src/c14n/serialize.rs
The serializer reports canonical structure to an observer. Existing canonicalization entry points use a no-op observer.
Typed input and source tape pipeline
src/xmldsig/transforms.rs, src/xmldsig/transforms/xslt.rs, src/xmldsig/transforms/xslt/source.rs
The XSLT executor accepts typed inputs. Node-set input is recorded as bounded canonical events and replayed through the document builder, while canonical byte size and parse limits are accounted for.
Source construction and execution tests
src/xmldsig/transforms/xslt/source/tests.rs, src/xmldsig/transforms/xslt/tests.rs
Tests compare tape-built documents with canonicalize-then-parse results and cover refusals, workspace use, and input accounting.

Mold build and benchmark linking

Layer / File(s) Summary
Mold linker configuration
.github/actions/rust-build-cache/action.yml, .github/workflows/ci.yml, benchmarks/Dockerfile, docs/benchmarks.md
The build-cache action adds an enabled-by-default mold option for Linux builds. The alloc-only job disables it. The benchmark image configures target-specific mold flags, which the instructions describe.

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant TransformAdapter
  participant XsltExecutor
  participant CanonicalSerializer
  participant SourceRecorder
  participant DocumentBuilder
  TransformAdapter->>XsltExecutor: pass typed node-set input and execution budget
  XsltExecutor->>CanonicalSerializer: canonicalize visible nodes with observer
  CanonicalSerializer->>SourceRecorder: report canonical structure
  SourceRecorder->>DocumentBuilder: replay semantic XML constructs
  DocumentBuilder-->>XsltExecutor: return built source document
Loading

Possibly related PRs

Merge Risk: Minimal · previous review 9cb86

No actionable merge-blocking risk remains from the reviewed evidence.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Out of Scope Changes check Warning The mold changes do not implement [#375]. They do not affect node-set source construction, the canonical-parse equivalence, or the XSLT workspace accounting. The changed files are: `.github/actions/ru… Remove the mold changes from this pull request. Specifically: revert the mold input and its steps in .github/actions/rust-build-cache/action.yml, revert the mold: 'false' line in .github/workflows/ci.yml, revert the mold installatio…
Docstring Coverage Warning Docstring coverage is 55.70% 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: 3 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 adds a tape-based path that builds the XSLT source document from a node-set's implicit C14N 1.0 form…
Linked Issues check Passed Issue [#375] requires that a node-set XSLT input build the source document without a canonicalization buffer or a second parse. It also requires the built tree, line numbers, source size, policy-limit…
Full details: Title check

Explanation

The title "perf(xslt): build node-set input without a second parse" matches the main change. The PR adds a tape-based path that builds the XSLT source document from a node-set's implicit C14N 1.0 form, replacing the buffer-and-reparse step. The objectives and linked issue #375 describe the same goal. The title is specific, uses a conventional commit prefix, and is under 72 characters. The mold linker changes and the observer plumbing are side effects and do not need to appear in the title.

Full details: Linked Issues check

Explanation

Issue [#375] requires that a node-set XSLT input build the source document without a canonicalization buffer or a second parse. It also requires the built tree, line numbers, source size, policy-limit behavior, and refusals to match a parse of the canonical octets. The head adds a CanonicalObserver in src/c14n/serialize.rs that reports canonical constructs, with () as the no-op observer for existing callers. It adds a public DocumentBuilder and Document::build_with_budget_reported in src/xslt/model.rs, which apply parse-equivalent source-byte, node, depth, namespace, and parse-work checks. It adds the tape-based source path in src/xmldsig/transforms/xslt/source.rs, which counts canonical octets, applies the XML input limits, and replays recorded constructs into the builder. src/xmldsig/transforms/xslt/source/tests.rs and src/xslt/model/builder_tests.rs compare built trees, source-byte counts, and refusals with parses of the canonical octets. Octet input keeps its existing path. The separate canonicalization buffer is removed from xslt::execute. Uncertainty: the tape stores canonical constructs in query storage. The issue does not name this storage. The PR charges its growth to the XSLT workspace, so this is treated as meeting the workspace requirement. Test results were not re-run in this review; the evidence is the diff summary and the test descriptions.

Full details: Out of Scope Changes check

Explanation

The mold changes do not implement [#375]. They do not affect node-set source construction, the canonical-parse equivalence, or the XSLT workspace accounting. The changed files are: .github/actions/rust-build-cache/action.yml (new mold input that installs mold and sets RUSTFLAGS, and disables rust-lld on X64), .github/workflows/ci.yml (sets mold: 'false' for the alloc-only job), benchmarks/Dockerfile (installs mold and sets per-target linker flags), and docs/benchmarks.md (documents the mold linker flags). The PR description also lists the CI linker change as a change and reports mold-linked Linux test results. The head still contains these changes, so the previous assessment's finding still holds. The XSLT, c14n, and xmldsig changes, including the memchr entry in the xslt feature, are not flagged. The memchr use is not confirmed by the summary alone.

Resolution

Remove the mold changes from this pull request. Specifically: revert the mold input and its steps in .github/actions/rust-build-cache/action.yml, revert the mold: 'false' line in .github/workflows/ci.yml, revert the mold installation and linker flags in benchmarks/Dockerfile, and revert the mold text in docs/benchmarks.md. If the linker change is still wanted, submit it in a separate pull request. Also remove the mold bullet from the PR description's Changes section and the mold-linked Linux test claim from its Testing section.

Full details: Docstring Coverage

Explanation

Docstring coverage is 55.70% 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 79 functions across 10 files.

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

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 c083997 and 9cb8603.

Files selected for processing: 4
  • src/xmldsig/transforms/xslt/source.rs
  • src/xmldsig/transforms/xslt/source/tests.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.

@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-03T10:09:26.774247Z 2999adc 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: 7435105faf

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

@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/xslt/model.rs Resolved
Comment thread src/xslt/model.rs Resolved
- the node-set recorder kept the prefixes in scope and each element's
  binding changes outside the workspace admission; they are now lists in
  the same storage whose growth is admitted with the tape's, the bound
  prefixes a sorted list the binding policy bounds
- DocumentBuilder::character_reference refuses characters XML 1.0
  excludes, as a parse refuses `�` or ``
- DocumentBuilder::start_element refuses `xmlns` and `xmlns:p` given as
  attributes, which a parse reads only as namespace declarations
- the CI mold step turns rust-lld off only on x86_64 runners, the one
  architecture where stable accepts that flag

Regression tests: namespace_bookkeeping_is_admitted_against_the_tape_limit
and references_and_attributes_no_parse_reads_are_refused_when_built.
@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the latest changes address the earlier findings without introducing a new actionable issue.

Summary

The PR builds XSLT input directly from a node-set’s canonical structure instead of keeping and reparsing canonical bytes. It also adds a public budget-aware document builder and selects mold for Linux builds.

The latest changes address all three earlier, unnumbered findings:

  • Node-set XSLT input builds its source tree without a second parse.
  • XSLT callers can build a document from XML constructs they already read.
  • Linux CI and benchmark builds link with mold.

No new actionable issues were found. This review checked source code; it did not run tests.

Reviews (2) · Last reviewed commit: "fix(xslt): refuse non-XML characters and..." · Reviewed by Greptile

Comment thread src/xslt/model.rs Resolved
Comment thread src/xslt/model.rs Resolved
Comment thread src/xmldsig/transforms/xslt/source.rs Resolved
- DocumentBuilder refuses literal text, comment, instruction, attribute
  and namespace values holding characters XML 1.0 production [2]
  excludes, as a parse does
- a namespace declaration's name is admitted with its URI before the
  prefix is copied, as a parse admits the attribute it reads
- an element past both the node and the depth limit of a node-set input
  is refused for the node limit, as the preflight of its octets reports

Regression tests: references_and_attributes_no_parse_reads_are_refused_
when_built (non-XML characters) and an_element_over_two_limits_is_
refused_for_the_one_a_parse_reports. The prefix admission changes only
the native peak and has no observable refusal to test. The XSLT 16384
verify benchmark shows no change in user CPU or minimum time.

@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: 9cb8603e56

ℹ️ 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
…tling

- DocumentBuilder checks a run for its forbidden sequence and for
  non-XML characters in one branch-free pass the compiler vectorizes;
  only a run holding a lead byte EF or the sequence's last byte takes the
  exact windowed pass, which also replaces the per-byte window rotation
  of the separate sequence scan
- element projection takes the lexical name by value and frees it before
  the staging charge that covers it is settled, so node storage and ID
  registration grow within what the meter admitted, as the parser did
  before projection was shared; this changes only the native peak, which
  no refusal shows
- an unprefixed element name built from parts is borrowed instead of
  copied

XSLT 16384 verify, both run orders: user CPU 66.4/66.5 ms -> 65.3/65.0
ms, minimum 76.3/75.9 ms -> 74.9/74.1 ms. A test covers a forbidden
sequence split across pieces.
@polaz
polaz merged commit 51cfc0b into main Nov 3, 2026
29 checks passed
@polaz
polaz deleted the perf/#375-xslt-input-once branch November 3, 2026 12:34
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