Skip to content

perf(bench): compare against competitors at CLI and library level - #314

Merged
polaz merged 19 commits into
mainfrom
perf/#298-competitor-levels
Oct 26, 2026
Merged

polaz merged 19 commits into
mainfrom
perf/#298-competitor-levels

Conversation

@polaz

@polaz polaz commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Benchmarks xml-sec against libxmlsec1 1.3.13 and Bergshamra at two levels and three document sizes.

  • CLI level: a fresh process per operation for every engine, across the main workloads (SAML response and assertion signing/verification with X509Data, XSW rejection, XMLEnc encrypt/decrypt, C14N, XPath and XSLT transforms).
  • Library level: in-process operations through each engine's API, with parse and prepared boundaries reported separately.
  • Sizes: 16, 256 and 16384 units. The 16384-unit documents are production-sized (about 0.5 to 1.7 MB), so per-byte cost is measured instead of being hidden behind process start-up.
  • Every case is validated before timing: signatures verify across engines, forgeries and XSW wrappings are rejected, and decryption returns the original plaintext on each boundary that is timed.
  • Allocation profiles come from separate instrumented builds. Peak heap counts the allocator's usable block sizes for every engine, so allocator rounding is charged the same way to all of them.
  • An operation an engine lacks, or refuses under its default resource policy, is recorded with its reason (exit 3) and never timed. A refusing engine is excluded from the cross-checks of that case only.
  • The dashboard and docs/benchmarks.md cover the three sizes.
  • Bergshamra lives only in the standalone benchmarks/competitors project with its own lockfile and a pinned revision; a test asserts the product dependency graph never contains it.

Includes the entity expansion ceiling fix from #312 (the 16384-unit SAML documents exposed it); those commits drop out once #312 lands. Stacked on #300.

Findings at 16384 units

These are from code without #305 and #307.

Testing

  • cargo nextest run --workspace (5158 passed, with the xmlsec1 1.3.13 oracle)
  • cargo clippy --workspace --all-targets -- -D warnings
  • Competitor project: cargo fmt --check, cargo clippy --all-targets with and without allocation-profile, cargo nextest run --features allocation-profile
  • node --test scripts/compare-security.test.mjs scripts/compare-library.test.mjs (26 passed)
  • Full local comparison at all three sizes: 320 CLI cases validated and 16 unsupported or refused; 107 library cases validated and 37 unsupported or refused.

Closes #298

polaz added 11 commits October 25, 2026 23:32
libxmlsec1 `encrypt --xml-data DATA --node-id ID TEMPLATE` fills the
first EncryptedData of the template, resolves ID in DATA, encrypts that
element (or its children for Content) and writes DATA with the
EncryptedData in place. The CLI applied --node-id to the template,
always encrypted the data root and wrote the rendered template, so an
element inside a document could not be encrypted.

- Resolve --node-id in the --xml-data document and replace the
  selected element or its children there; output the data document.
- Take the template from its first EncryptedData.
- Refuse templates whose EncryptedData refers to other template nodes
  by #id, since only the EncryptedData moves into the data document.
- Accept --session-key aes-128|aes-192|aes-256 when it matches the
  template AES method and an EncryptedKey recipient carries the key.

The process-contract tests that asserted template-subtree selection and
content-only decryption output now assert libxmlsec1's behavior, checked
against the pinned 1.3.13 CLI. A reciprocal oracle test encrypts an
element in place with RSA-OAEP and AES-256-GCM in both directions.

Closes #299
- Select the data node by --node-name as libxmlsec1 does: split at the
  last colon into namespace URI and local name, take the first element
  in document order with that expanded name, and fail with "failed to
  find node with name" otherwise. --node-id still takes precedence.
- Refuse output that exceeds the XML document limit once the filled
  EncryptedData replaces the selected node, instead of writing a
  document the CLI cannot read back.
- Resolve XPointer references of the moved EncryptedData with the same
  dereferencing the core uses, so a #xpointer(id('x')) reference to a
  template node outside it is refused like a bare #x.

Regression tests: xml_data_node_name_selects_the_first_matching_element,
xml_data_output_obeys_the_document_limit and
xml_data_template_references_resolve_xpointer_forms. The node-name
selection matches the pinned libxmlsec1 1.3.13 CLI on the same inputs.
- Parse the assembled --xml-data document under the full operation
  policy before writing it. The data document and the filled template
  each fit their limits, but a leaf replaced at the depth limit nests
  the EncryptedData children beyond it, and decryption refused the
  written output.
- Undeclare the default namespace on the moved EncryptedData when the
  template has none and its new parent provides one, so unprefixed
  template metadata keeps its expanded name (Namespaces in XML 1.0,
  section 6.2).
- Check same-document references with the element resolution the core
  key-source parser uses instead of projecting the target subtree per
  URI, which was quadratic in templates with many references. A
  #xpointer(/) reference is refused: after the move it would select the
  data document.

Regression tests: xml_data_output_obeys_the_structural_limits,
xml_data_moved_template_keeps_its_absent_default_namespace and the
#xpointer(/) case of xml_data_template_references_resolve_xpointer_forms.
- Resolve the moved EncryptedData's references in the assembled data
  document, where decryption resolves them, and require an unambiguous
  target inside the moved element. A template ID that the data document
  also uses passed the template-only check, and decryption then refused
  the ambiguous reference.
- Keep a template's own `xmlns=""` instead of adding a second one, which
  made the opening tag carry a duplicate attribute (Namespaces in XML
  1.0, section 6.3) and refused the template.

Regression tests: xml_data_references_stay_unambiguous_in_the_data_document
and xml_data_moved_template_keeps_its_own_default_undeclaration.
The self-containment check treated every `URI` attribute under the moved
EncryptedData as a reference, so application metadata in
EncryptionProperty (XMLEnc 1.1 section 3.7), which decryption never
resolves, made a valid template look dangling. Only CipherReference,
RetrievalMethod, KeyInfoReference, DataReference and KeyReference are
checked now; other `URI` attributes are preserved as they are.

Regression test: xml_data_ignores_uri_attributes_of_extension_metadata.
The CLI comparison measured only signed payloads and byte-oriented
symmetric encryption. Add the workloads applications run:

- SAML assertion sign and verify; verification trusts only a root CA
  and receives the signer certificate and an untrusted intermediate.
- Element encryption to an RSA-OAEP recipient certificate, standalone
  and in place inside its document.
- A reference transformed by an XSLT stylesheet.

Every output is verified or decrypted by every engine before timing,
and each engine must reject a changed signed value. Capabilities the
pinned Bergshamra CLI lacks (XSLT, in-place element encryption) are
recorded as unsupported with the reason and never timed. The report
schema and the dashboard carry the new workloads.

Part of #298
An identity provider writes its certificate into the signature, and a
relying party must reject signature wrapping. The assertion workload
now signs with key and certificate into an empty X509Data, verifies
the result through the trusted root without rewriting KeyInfo, and
requires every verifier to reject a forged assertion that repeats the
signed ID ahead of the signed one.

Unsupported work is recorded per operation: Bergshamra leaves X509Data
empty and cannot encrypt in place, but it verifies the other engines'
assertions and decrypts their in-place documents, so those operations
are measured.

Part of #298
Process launch and key loading dominate the CLI comparison for small
documents, so it cannot show what one operation costs. Add a library
level, reported in its own dashboard section and never ranked against
the CLI level:

- xml-sec through its Rust API, Bergshamra through its Rust API from
  benchmarks/competitors (a project outside the workspace with its own
  lockfile and the pinned revision), and libxmlsec1 through its C API;
- parse-and-operation and prepared-document boundaries for the SAML
  assertion, element, in-place element and XSLT workloads;
- every result each engine produces is consumed by every other engine
  before timing, and every verifier must reject the tampered and the
  wrapped input; a harness reports an operation its engine lacks with
  the reason, recorded as unsupported and never timed;
- allocation counts come from separate instrumented builds: a counting
  global allocator for Rust and, on glibc, a malloc-family replacement
  for C.

The tracked ignore file keeps only build artifacts of the project and
the competitor lockfile it publishes.

Part of #298
Both comparison levels measured only 16 and 256 repeated units (at most
27 KB), where libxmlsec1's fixed process cost dominates and per-byte cost
is invisible. Every CLI payload shape, workload and library case now also
runs at 16384 units: the SAML response is about 1.7 MB, the other shapes
0.25-1.7 MB. The in-repository Divan benches keep their sizes.
The xmloxide backend charged predefined references, character references
and predefined references inside entity replacement text against the
entity expansion ceiling, documented as the limit on general-entity
substitutions. None of them substitutes a declared entity or amplifies
input, so a well-formed document with more than 10000 escaped
characters (for example `
` in certificate base64 or `&` in
URLs) was refused. Only references to declared entities are charged
now, matching the lexical preflight and the roxmltree backend; the
document byte ceiling and the replacement-work ceiling still bound the
others.

Regression tests: entity_ceiling_tests runs on every compiled backend.
The parser's own limit tests now count declared entities instead of
predefined and character references.

Closes #311
- Harnesses report a resource-limit refusal under the engine's default
  policy as unsupported work with its reason (exit 3) instead of failing
  the whole comparison.
- The comparison runners take the canonical result from the first engine
  that produced one and exclude refusing verifiers from rejection checks,
  so a 16384-unit workload one engine refuses is still validated across
  the others.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

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 24 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 2165269 and 3767ca4.

Files ignored due to path filters: 1
  • benchmarks/competitors/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 24
  • .github/workflows/benchmark-comparison.yml
  • .gitignore
  • benches/support/mod.rs
  • benchmarks/competitors/Cargo.toml
  • benchmarks/competitors/src/bin/bergshamra_library.rs
  • benchmarks/competitors/src/bin/xml_sec_library.rs
  • benchmarks/competitors/src/lib.rs
  • benchmarks/competitors/src/tests.rs
  • benchmarks/dashboard/app.js
  • benchmarks/dashboard/index.html
  • benchmarks/dashboard/style.css
  • benchmarks/libxmlsec1-library.c
  • docs/benchmarks.md
  • examples/benchmark_latency.rs
  • scripts/benchmark-compare.sh
  • scripts/build-benchmark-dashboard.mjs
  • scripts/compare-library.mjs
  • scripts/compare-library.test.mjs
  • scripts/compare-security.mjs
  • scripts/compare-security.test.mjs
  • scripts/patches/xmloxide-0.5.0.patch
  • src/document.rs
  • src/document/entity_ceiling_tests.rs
  • src/parser_xmloxide/parser/input.rs
  • 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 commented Oct 25, 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-26T06:15:54.786054Z a750c71 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: bac1866e84

ℹ️ 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 scripts/compare-library.mjs Resolved
Comment thread benchmarks/libxmlsec1-library.c Resolved
polaz added 5 commits October 26, 2026 02:11
- Every consuming probe now writes its own result, and decryption output
  is compared with the plaintext on the prepared boundary as well as the
  parse boundary. A prepared decryptor that returned other content was
  timed and published as validated. Regression test: a fake harness that
  is wrong only on the prepared boundary stops the run.
- The Rust allocation profile counts live bytes as the allocator's usable
  block sizes, as the glibc profile of the C harness does, so the peak
  heap metric includes allocator rounding for every engine. Regression
  test: a one-byte allocation charges its whole block.
The vendored parser is verified against upstream 0.5.0 plus the
maintained delta; regenerate the delta so it carries the entity
expansion ceiling change and the verification step passes.
…erf/#298-competitor-levels

# Conflicts:
#	src/document.rs
The in-process libxmlsec1 harness parsed with XML_PARSE_NONET alone, so
each document interned its names in its own dictionary. Element
encryption moves the template node into the data document; with
libxml2 2.9 the moved names stay in the template's dictionary and are
later passed to free() with the data document. glibc aborts on that,
which stopped the Linux comparison at the first encryption probe.

The harness now parses with xmlSecParserGetDefaultOptions(), the
options the xmlsec1 command line uses, including XML_PARSE_NODICT.

The defect needs glibc with libxml2 2.9 to show; macOS, including its
guard allocator, does not abort. The Linux comparison job is the
regression check: it failed at this probe before the change.
Base automatically changed from fix/#299-encrypt-node-id to main October 26, 2026 06:43
@polaz
polaz enabled auto-merge (squash) October 26, 2026 06:50
@polaz
polaz merged commit 7283e3f into main Oct 26, 2026
30 checks passed
@polaz
polaz deleted the perf/#298-competitor-levels branch October 26, 2026 08:03
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: compare main scenarios against competitors at CLI and library level

1 participant