Skip to content

perf(c14n): reuse the namespace declaration list - #392

Merged
polaz merged 1 commit into
mainfrom
perf/#391-start-tag-declarations
Nov 4, 2026
Merged

polaz merged 1 commit into
mainfrom
perf/#391-start-tag-declarations

Conversation

@polaz

@polaz polaz commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Canonicalization reuses one namespace declaration buffer across start tags, as it already does for attributes, so Exclusive C14N no longer allocates a list per element that redeclares a prefix.
  • A regression test pins the allocation count of a whole canonicalization so that it does not depend on the number of start tags.

Changes

  • NsRenderer::render_namespaces and collect_ns_declarations fill a caller-owned, empty declaration list and return only the rendered map.
  • The canonical output owns the declaration buffer beside the attribute buffer and empties both after each start tag. Accounted storage keeps the capacity charged.
  • Attribute collection moves out of serialize_start_tag into collect_start_tag_attributes; output is byte-identical.
  • tests/c14n_allocations.rs counts allocations with a global allocator and requires the same count for 16 and 256 elements in every mode, with and without comments.

Testing

Library unit tests, the C14N golden and integration suites, the new allocation test, clippy with all features and formatting pass on macOS. The allocation test fails against a per-tag declaration list (Exclusive) and against a per-tag attribute list (Inclusive).

Closes #391

Summary by CodeRabbit

  • Improvements
    • Canonicalization now uses a more consistent number of fresh memory allocations as document size grows.

- The canonical output owns a declaration buffer beside the attribute
  buffer; the namespace renderer fills it for each start tag, and it is
  emptied before the next one. Exclusive C14N, which redeclares a prefix
  on every element that uses it below a non-utilizing ancestor, no
  longer allocates a list per such element.
- Attribute collection moves out of serialize_start_tag into its own
  function; output is byte-identical in every mode.
- An allocation-counting test pins the allocations of a whole
  canonicalization to the same count for 16 and 256 elements in every
  mode, so a per-tag declaration or attribute list fails it.

Closes #391
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-04T21:15:58.273927Z c96bdc4 PR opened
ℹ️ 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 Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Canonicalization now reuses namespace declaration and attribute buffers across start tags. Namespace renderers fill the declaration buffer supplied by the serializer. A new allocation-counting test compares results across document sizes, canonicalization modes, and comment settings.

Changes: Canonicalization buffer reuse

Layer / File(s) Summary
Separate and populate namespace declarations
src/c14n/scratch.rs, src/c14n/ns_common.rs, src/c14n/ns_inclusive.rs, src/c14n/ns_exclusive.rs
Declarations now represents namespace declarations separately from the child-read namespace map. Namespace renderers pass a caller-provided declaration buffer to collect_ns_declarations, which asserts that the buffer is empty on entry and returns only the rendered map.
Reuse buffers during start-tag serialization
src/c14n/serialize.rs, tests/c14n_allocations.rs
CanonicalOutput stores reusable declaration and attribute buffers. Start-tag serialization fills and sorts attributes, emits the start tag, then clears and restores both buffers. The new test checks that fresh allocation counts match for 16- and 256-element documents across three C14N modes and both comment settings.

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

Change: Refactor

Merge Risk: Minimal · up to c96bd

The change reuses canonicalization buffers; no material merge risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% 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(c14n): reuse the namespace declaration list" matches the main change. The raw summary says collect_ns_declarations and the renderers now receive a reusable mutable Declarations buffer …
Linked Issues check Passed Issue #391 is directly linked and open. The PR adds a reusable CanonicalOutput::declarations buffer beside the attribute buffer. render_namespaces and collect_ns_declarations fill that caller-ow…
Out of Scope Changes check Passed The changes stay within issue #391. Namespace collection changes implement declaration-buffer reuse. Attribute collection moves into a helper so the existing attribute buffer remains reusable. The all…
Full details: Title check

Explanation

The title "perf(c14n): reuse the namespace declaration list" matches the main change. The raw summary says collect_ns_declarations and the renderers now receive a reusable mutable Declarations buffer instead of allocating a new list per start tag. The title uses a conventional commit prefix and names the primary change. It does not mention the new allocation-counting test, but the title does not need to cover every detail.

Full details: Linked Issues check

Explanation

Issue #391 is directly linked and open. The PR adds a reusable CanonicalOutput::declarations buffer beside the attribute buffer. render_namespaces and collect_ns_declarations fill that caller-owned buffer, and serialize_start_tag empties it after each start tag. The new tests/c14n_allocations.rs compares 16 and 256 elements in all three C14N modes, with and without comments. The reported golden and integration suites cover byte-identical output.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #391. Namespace collection changes implement declaration-buffer reuse. Attribute collection moves into a helper so the existing attribute buffer remains reusable. The allocation test verifies the requested regression behavior. No unrelated production behavior or unrelated tests are introduced.

Full details: Docstring Coverage

Explanation

Docstring coverage is 37.50% 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 8 functions across 6 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
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0ff04d4 and c96bdc4.

Files selected for processing: 6
  • src/c14n/ns_common.rs
  • src/c14n/ns_exclusive.rs
  • src/c14n/ns_inclusive.rs
  • src/c14n/scratch.rs
  • src/c14n/serialize.rs
  • tests/c14n_allocations.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.

@polaz
polaz enabled auto-merge (squash) November 4, 2026 21:26
@polaz
polaz merged commit d14fec6 into main Nov 4, 2026
29 checks passed
@polaz
polaz deleted the perf/#391-start-tag-declarations branch November 4, 2026 21:44
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(c14n): reuse the namespace declaration list across start tags

1 participant