Skip to content

perf(dsig): store node sets as ranges, vectors or bitsets - #237

Merged
polaz merged 3 commits into
mainfrom
perf/#236-compact-node-sets
Oct 18, 2026
Merged

polaz merged 3 commits into
mainfrom
perf/#236-compact-node-sets

Conversation

@polaz

@polaz polaz commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Node sets produced by same-document references and transforms no longer store one hash-table entry per selected node: whole-document and subtree projections are index ranges minus excluded subtrees, explicit XPath and Filter 2.0 results are sorted index vectors or bitsets.
  • Accept/reject behaviour, limit values and error kinds are unchanged; set algebra stays exact across representations.

Changes

  • The parsed document assigns every XPath node a document-order index; a node's attributes and namespaces follow it, so a subtree is one contiguous range. A document whose index space exceeds u32 is rejected as a node-limit violation.
  • URI="", #id and enveloped-signature exclusion keep a range plus sorted excluded subtree ranges, with no per-node storage.
  • Explicit sets are sorted u32 vectors with a one-bit-per-64-indexes block summary while sparse, and bitsets from 1/128 of the document's nodes (threshold measured by the new node_set_* benchmarks, see docs/benchmarks.md).
  • Union, intersection, subtraction and subtree exclusion work across all three representations; reads of a right-hand operand are charged to the current query.
  • Cardinality and owned name bytes are cached, so node-set entry, owned-string and filter-work limits are charged with the same values as before.

Testing

  • Randomized tests compare every representation with a model of the previous hash set on element, attribute and namespace membership and on canonical bytes in all C14N modes.
  • fmt, clippy, the full nextest suite (including donor corpora and the xmlsec1 oracle), doctests and the no-std checks pass locally on macOS.

Closes #236

Summary by CodeRabbit

  • Performance

    • Improved processing of large XML node sets, including sparse and dense selections, with more efficient storage and set operations.
    • Reduced memory pressure when working with subtree projections.
  • Bug Fixes

    • Subtree replay can now succeed within a limited query budget in cases that previously failed before delivering results.
  • Documentation

    • Clarified node-set entry limits and memory accounting for attribute and namespace names, including the default limit and caller-adjustable ceiling.

- Index every XPath node in document order when the semantic arena is
  built; a subtree with its attributes and namespaces is one index range.
- Keep whole-document and subtree projections, minus excluded subtrees, as
  arena ranges: URI="", #id and enveloped exclusion store no per-node keys.
- Store XPath and Filter 2.0 results as sorted index vectors with a block
  summary while sparse, and as bitsets from 1/128 of the document's nodes.
- Keep set algebra exact across representations, charge right-hand reads
  to the current query, and keep entry, name-byte and filter-work limits
  at the values the per-node table charged.

Measured against the previous hash table (16K elements, inclusive C14N):
enveloped projection 17.7 ms -> 4.2 ms with peak memory 6.5 MB -> 1.05 MB
(mostly the canonical output); explicit selections 3.5-4.5x faster.
Randomized tests compare every representation with the previous table on
tree, attribute and namespace membership and on canonical bytes.

Closes #236
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-10-18T09:38:24.914664Z 0b172f9 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.

@coderabbitai

coderabbitai Bot commented Oct 18, 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 21 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: Repository: structured-world/xml-sec/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c8cd18e-ba28-45c0-8e36-3936c5e8adc2
📥 Commits

Reviewing files that changed from the base of the PR and between d1cb242 and 0b172f9.

📒 Files selected for processing: 2
  • src/xmldsig/types/projection.rs
  • src/xmldsig/types/projection/tests.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: structured-world/xml-sec/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d1ca2496-91ee-4b7e-836c-f17c2cf3e689
📥 Commits

Reviewing files that changed from the base of the PR and between c1ca566 and d1cb242.

📒 Files selected for processing: 5
  • docs/benchmarks.md
  • src/benchmark_support.rs
  • src/xml/dom/tree.rs
  • src/xmldsig/types/projection.rs
  • src/xmldsig/types/projection/tests.rs
🚧 Files skipped from review as they are similar to previous changes: 1
  • docs/benchmarks.md

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

XMLDSig node sets now use semantic subtree ranges or explicit sparse and dense representations. The change adds document-order XPath indexes, updates projection operations and execution accounting, and adds validation tests and node-set benchmarks.

Changes: Adaptive node-set projections

Layer / File(s) Summary
Document-order XPath indexes
src/xml/dom/tree.rs
The XML tree assigns document-order XPath indexes to tree, attribute, and namespace nodes. Document and node helpers expose index counts, ownership, and subtree ranges.
Projection representations and membership
src/xmldsig/types/projection.rs
Projections use semantic subtree ranges, sorted sparse indexes, or dense bitsets. Membership, iteration, insertion, and compaction use document-order indexes.
Set operations and XMLDSig integration
src/xmldsig/types/projection.rs, src/xmldsig/types.rs, src/xmldsig/transforms.rs, src/xmldsig/xpath.rs, src/policy.rs
Projection set algebra operates on XPath indexes and records execution failures. XMLDSig transform and XPath code uses the revised keys interface. Resource-policy documentation describes node-entry and name-byte limits.
Projection validation and benchmarks
src/xmldsig/types/projection/tests.rs, tests/authenticated_reference_replay.rs, src/benchmark_support.rs, benches/security.rs, docs/benchmarks.md
Tests compare projections with a reference set and check canonical output, budget failures, and memory release. Replay coverage expects subtree projection output. Benchmarks measure enveloped, sparse, and dense node sets.

Priority: ➖ Normal

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to d1cb2

The change replaces node-set storage with more compact representations while keeping the stated accept/reject behavior and resource limits. No actionable merge-blocking risk was identified in the supplied context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.20% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 125 functions across 10 files. (1 skipped… 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 performance change: representing XMLDSig node sets with ranges, vectors, or bitsets.
Linked Issues check Passed Issue #236 is active and directly linked. The PR implements range-based subtree projections, sparse indexed vectors, and dense bitsets. The implementation assigns bounded document-order indexes and su…
Out of Scope Changes check Passed The changes stay within issue #236. Tree indexing supports compact node-set indexes. Projection changes implement representation selection and exact set algebra. Tests cover required behavior and acco…
Full details: Linked Issues check

Explanation

Issue #236 is active and directly linked. The PR implements range-based subtree projections, sparse indexed vectors, and dense bitsets. The implementation assigns bounded document-order indexes and supports exact set algebra across representations. Tests compare the compact representation with the previous hash-set model for tree, attribute, and namespace nodes and verify canonical output. The tests also cover resource-limit failures, current-query work charging, and storage release. docs/benchmarks.md and src/xmldsig/types/projection.rs document measured sparse/dense selection and peak-memory allocation runs. The PR reports donor-corpus byte equality and preserved failure classes.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #236. Tree indexing supports compact node-set indexes. Projection changes implement representation selection and exact set algebra. Tests cover required behavior and accounting. Benchmark helpers and documentation measure time, memory, and the density threshold. The replay test updates an expectation for the changed compact-projection capacity behavior. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 35.20% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 125 functions across 10 files. (1 skipped: 1 unsupported.)

Resolution

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

✨ Finishing Touches: 💡 1
📝 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

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

@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: c1ca5667be

ℹ️ 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/types/projection.rs Resolved
Comment thread src/xmldsig/types/projection.rs Resolved
@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] No outstanding findings block merging the reviewed changes.

Summary

The PR replaces per-node hash entries with subtree ranges, sorted vectors, or bitsets. The latest changes charge query work for explicit filtering, removed attributes and namespaces, searches, and exclusion-list moves.

  • XML signature node sets use compact storage for selected nodes.

Reviews (3) · Last reviewed commit: "fix(dsig): pay every member examined by ..." · Reviewed by Greptile

Comment thread src/benchmark_support.rs Resolved
- Inserting an index already present in a whole-document or subtree
  projection no longer copies it into explicit storage first, so a
  union that adds nothing cannot fail on the query's memory account.
- Walking members charges execution work for every emitted index,
  including each attribute and namespace node of a semantic subtree.
- Compute the document-order XPath index only with XML signatures; the
  C14N-only build no longer carries the unused index.
- The node-set benchmarks build each selection directly in the measured
  representation instead of converting after an automatic promotion;
  the threshold comment carries the re-measured medians.

Regression tests cover the present-member union under a small memory
account and the per-index work of materializing an attribute-heavy
element.

@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: d1cb242185

ℹ️ 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/types/projection.rs Resolved
Comment thread src/xmldsig/types/projection.rs Resolved
- Filtering an explicit set charges one work unit per examined member in
  the sparse vector and per member held by each scanned bitset word, so
  a subtree exclusion that removes nothing still pays for its scan.
- Excluding a subtree from a semantic projection charges each removed
  node's attribute and namespace axes, the search for its position among
  earlier exclusions and the exclusions moved to make room.

Regression tests cover a no-op exclusion from sparse and dense explicit
sets and the removal of an element with 4096 attributes.
@polaz
polaz merged commit eb2ef6a into main Oct 18, 2026
44 checks passed
@polaz
polaz deleted the perf/#236-compact-node-sets branch October 18, 2026 10:00
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(dsig): adaptive compact node-set representation

1 participant