Skip to content

Comparison: one run per stretch, one read per parent, references and resplit controls (#446 case 1) - #450

Open
hadim wants to merge 5 commits into
tensorbee:mainfrom
hadim:fix/446-compare-runs-and-reads
Open

hadim wants to merge 5 commits into
tensorbee:mainfrom
hadim:fix/446-compare-runs-and-reads

Conversation

@hadim

@hadim hadim commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Part of #446 (case 1). Five commits on main eb980e9 (v0.17.0): the four changes below, then the archive row.

Context: why a change of this size

The report. Case 1 of #446: compare(..., granularity="word") in 0.17.0 writes every character of a changed
paragraph as its own w:r, and each deleted or inserted letter as its own w:delText or w:t. For the issue's 200
paragraphs that is 17,180 runs and 517 KiB of document.xml where 0.16.4 wrote 6,200 runs and 245 KiB, and the
comparison takes 10 times as long. The comment on the issue adds that the default run granularity is about 4 times
slower than 0.16.4 with the same output, so the slowdown has a cause of its own.

Four causes from three v0.17.0 rewrites. None of them is in the alignment, and each is a reasonable step of
the feature that introduced it:

cause introduced by effect
character units reach the output F-X279b, 2d38731 (issue #434 case 3) one run per character at word granularity
the postcondition signature reads one token per character F-X279b, 2d38731 cost per character of four documents at every granularity
the source guard reads a parent again for each child F-X272, af99e9d quadratic in the runs of a paragraph and the rows of a table
the footnote destination check resolves the candidate again F-X272a, 1c69b7e two extra resolutions per comparison

Why one pull request. The first cause decides the shape of the output and the other three its cost. Fixing the
shape alone left one long paragraph quadratic in its runs and the default run granularity 4 times slower than 0.16.4.
Fixing the reads alone left the output twice the size of 0.16.4's. Each commit stands on its own and states its own
guard.

The size is exceptional. Most of the diff is in comparison.rs and it is in two families: the two helpers every
granular path shares (coalesced_granular_alignment, merge_unit_runs), and the readers that answer every child of
a parent from one read (RunSource::capture_all, publication_parents_at, source_children, ParentScopes),
applied where the old code read once per child. It is not a pattern for other changes.

Two fixes ride along, both found while checking the siblings of the paths above: word and character comparisons
refused any changed text holding a reference such as & (also since af99e9d), and an inline content control
whose runs only split the same text differently was compared run by run (since 0.16.4).

The causes and the fixes

1. Character units reach the output (commit 1)

Since v0.17.0 a word comparison aligns logical words over character units, so that a word split across runs compares
equal (compare_granular_paragraph, coalesced_words). Nothing joined the units again before writing:
coalesced_granular_alignment grouped the pairs of a change but never the unchanged ones, and merge_unit_runs wrote
one text element per unit.

The granularity now sets what is compared, never how the result is cut. Two rules, in the two helpers that the
paragraph path and the inline-control path share, so they hold at every granularity, in every story and for
inserted and deleted text alike:

  • coalesced_granular_alignment keeps unchanged pairs together while they continue the same original and the same
    edited text element, as it already kept the pairs of one change together.
  • merge_unit_runs joins consecutive fragments of one text element into one text with one source selection, whole
    again when every fragment is there, so a fully unchanged element is published from its source as at run
    granularity.

2. The postcondition signature reads one token per character (commit 2)

The acceptance and rejection postconditions compare normalized packages. For an ordinary part the signature is taken
at character granularity so that run splits do not change it (coalesced_postcondition_body). It built one unit, one
copy of the run properties and one token per character of the candidate resolved both ways, the original and the
edited document.

A run with no raw child and no deleted text is now read one stretch at a time, and consecutive plain characters are
one token (signature_run_units, signature_scalars, ParagraphToken::Scalars), in paragraphs and in the direct
runs of a control. A run holding a raw child or deleted text keeps its units per character, because those belong to
single characters.

3. The source guard reads a parent again for each child (commit 2)

F-X272 checks the comparison against the physical source. Its helpers read a parent from its start for each child:
RunSource::capture for each run of a paragraph, publication_parent_at and source_child for each row of a table,
cell of a row, child of a cell or a control, inline control and field of a paragraph. This happens in the five source
snapshots of a comparison and again in the compare and mark paths: compare_table, compare_row,
compare_cell_from_xml, compare_granular_controls, compare_complex_paragraph, paragraph_children_xml, the marked
rows and cells of an inserted or deleted table, and the parent of each written piece in compare_granular_paragraph.
The cost is quadratic in the children: growth for 4 times the rows of a table was 7.0 on v0.17.0, and 8.8 at word
and 10.2 at character for 4 times the runs of one paragraph on the first version of this branch.

RunSource::capture_all, publication_parents_at and source_children read a parent once for all the positions
asked. Each keeps the loop of the single-position function it replaces, so the answer for each position, an error
included, is the one a read for that position alone gives, and each answer is taken where that read was made, so
errors keep their order. ParentScopes asks publication_parents_at for every run edge of a paragraph on its first
question, and reads a position outside that set alone. publication_parent_at and source_child remain as the
one-position form of the same loop.

4. The footnote destination check resolves the candidate again (commit 2)

Each postcondition direction resolved the candidate for the package guard, then verify_footnote_destination cloned
and resolved it again. resolved_candidate resolves it once per direction and both checks read that document.

Ride-along A: text holding a reference (commit 3)

source_text_fragment (af99e9d) checks that the source of a split text is one element holding text, and accepted
exactly one text event. quick-xml 0.41 reports & or é as a GeneralRef event between two text events,
so every word or character comparison of a changed paragraph holding a reference refused with "split text has opaque
mixed events", in the body and in related stories. That includes &, <, > and ", which rdocx
writes itself on save: saving and reopening "Smith & Sons pay now." and comparing it with "... later." refused.
0.16.4 compared it. Any number of text and reference events now pass at the text's depth. Nested elements, CDATA,
comments and processing instructions still refuse. The value comes from the parsed model and is escaped again on
output, as before.

Ride-along B: a resplit inline control (commit 4)

A paragraph whose runs only split the same text differently compares equal since v0.17.0. An inline content control
did not, since its runs were aligned one by one: one run against three with the same text and formatting gave 4
revisions at run granularity, as in 0.16.4. A word redline of one sentence inside a control, accepted or rejected and
compared again with its input, gave 25 revisions (word) and 70 (character) on 0.16.4 and v0.17.0. When every child of
both controls is a run and the runs differ, compare_control_from_xml now applies the equality the paragraph path
already trusts (coalesced_paragraphs_equal) and keeps the original source when it holds.

How the guarantees are kept

guard site before after proof that it is the same
acceptance and rejection postconditions resolve the candidate in resolved_package, resolve it again in verify_footnote_destination resolved_candidate once per direction, both checks read it the second resolution was a fresh clone of the same candidate resolved with the same ids and projected the same way, so both checks read an identical document
run sources of the snapshots RunSource::capture per run RunSource::capture_all, one read same event loop, same error per position (read error, namespace binding error, "run source has no actual opening"), each result taken where the single capture was, field fragments still captured in their turn. A unit test compares every answer with a lone capture, an error included
parent scope and scoped child of rows, cells, cell children, control children, inline controls, fields publication_parent_at and source_child per child publication_parents_at and source_children, one read per parent same loop and messages as the single-position functions, which are now their one-position form. Answers are taken in the original order. A unit test compares together and alone, errors included, positions out of order
postcondition signature of an ordinary part one token per character one token per stretch of plain characters a stretch token reads the concatenation of the character tokens it replaces, so two signatures are equal exactly when their character tokens were. Raw children and deleted text keep per-character units. A unit test covers splits, tabs, empty text, ignored whitespace and controls
run spans of a paragraph snapshot computed twice computed once same function on the same input
package guard of each story (v0.17.0) second read of the cleaned clone in project_source_body unchanged, byte for byte a regression pins the refusal that read makes (see "Findings in no issue")
resplit inline control aligned run by run coalesced_paragraphs_equal on the control's runs the body path's own equality, not applied under leaf capture, to a control holding a raw child or a revision, or to runs holding a field, whose source facts cannot be read from copies

On top of the unit tests, three differential sets against the v0.17.0 release wheel, all on a debug build with every
debug oracle on:

  • 1,080 refusal-map cases around existing revisions, notes, comments, moves, controls, fields, bookmarks and related
    stories: same refusals, same messages, inputs intact.
  • 792 guard cases (drawings, VML and DrawingML text boxes, hyperlinks, fields and controls, with and without
    ignore_formatting): same refusals, same messages, same bytes at run granularity.
  • 500 format-aware random pairs (seed 7 of the review's generator): same accepted and rejected text and
    per-character formatting. Insertions, deletions and run-granularity bytes are the same except in 3 pairs, each a
    pure resplit inside an inline control where v0.17.0 wrote a revision (ride-along B).

Behaviour changes

  • Word and character redlines hold one run per revision and one per stretch of unchanged text between revisions,
    whatever the unit, in every story. Each revision holds its text in one w:t or w:delText.
  • A whole-run formatting change at word or character granularity is one w:rPrChange per unchanged stretch, against
    one per word in 0.16.4 and one per character in v0.17.0.
  • Two cases still cut a stretch: under ignore_whitespace an ignored whitespace unit ends a stretch, so unchanged
    text is one run per word and per space (as in 0.16.4), and a tab or a break ends a stretch as it ends a text
    element.
  • Run-granularity output is byte for byte the output of v0.17.0, except an inline control whose runs only split the
    same text differently, which keeps its source where v0.17.0 wrote a revision.
  • Word and character comparisons accept changed text holding a character or entity reference, which v0.17.0
    refused.
  • The refusals of v0.17.0 are otherwise unchanged, messages included.
  • p.runs of a word or character redline returns the stretches and revisions, not one run per character.

Numbers

Method: CPU time of compare() alone, median of 5 runs alternated call by call between the three builds, on one
machine (Apple M5 Max, macOS). 0.16.4 and v0.17.0 are the PyPI release wheels (fat LTO, one codegen unit). This branch
is a release build with LTO off and 16 codegen units, which makes its ratios pessimistic. Cases are the issue's
scripts and the cases of the review (bench_worker.py): one paragraph of 400 runs with one word changed, and a table
of 100 rows of 6 cells with one cell in 10 changed.

case granularity 0.16.4 v0.17.0 this branch against 0.16.4 against v0.17.0
issue 446, 200 paragraphs changed run 0.108 s 0.443 s 0.309 s 2.87 0.70
issue 446, 200 paragraphs changed word 0.637 s 6.653 s 0.453 s 0.72 0.07
issue 446, 200 paragraphs changed character 1.736 s 6.953 s 0.764 s 0.44 0.11
issue 446, 400 paragraphs changed run 0.209 s 0.890 s 0.620 s 2.95 0.69
issue 446, 400 paragraphs changed word 1.379 s 14.403 s 0.941 s 0.70 0.07
1000 paragraphs, 100 changed run 0.327 s 1.143 s 0.813 s 2.48 0.72
1000 paragraphs, 100 changed word 0.731 s 4.325 s 0.943 s 1.29 0.22
1000 paragraphs, 100 changed character 1.566 s 4.616 s 1.014 s 0.65 0.22
one paragraph of 400 runs run 0.056 s 0.532 s 0.118 s 2.14 0.22
one paragraph of 400 runs word 0.092 s 9.286 s 0.146 s 1.58 0.02
one paragraph of 400 runs character 0.309 s 9.311 s 0.170 s 0.55 0.02
table of 100 rows run 0.207 s 1.743 s 0.879 s 4.22 0.50
table of 100 rows word 0.330 s 2.341 s 0.954 s 2.89 0.40
100 paragraphs with a footnote, 10 % changed run 0.089 s 0.355 s 0.311 s 3.52 0.88
100 paragraphs with a footnote, 10 % changed word 0.121 s 0.520 s 0.331 s 2.80 0.64

Growth of the time for 4 times the children, within one build, median of 3:

case granularity 0.16.4 v0.17.0 this branch
one paragraph, 500 to 2000 runs run 3.85 13.16 4.35
one paragraph, 500 to 2000 runs word 4.44 4.59
one paragraph, 500 to 2000 runs character 6.22 7.70
table, 50 to 200 rows run 4.15 6.91 4.22
table, 50 to 200 rows word 3.97 6.85 4.23

v0.17.0 was not timed at word and character on the long paragraph, where one comparison of 2000 runs takes over a
minute and a half. Output of the issue's 200 paragraphs:

granularity 0.16.4 v0.17.0 this branch
run 76 KiB, 200 runs, 400 revisions 76 KiB, 200 runs, 400 revisions 76 KiB, 200 runs, 400 revisions
word 245 KiB, 6,200 runs, 400 revisions 517 KiB, 17,180 runs, 400 revisions 76 KiB, 600 runs, 400 revisions
character 540 KiB, 17,980 runs, 800 revisions 541 KiB, 17,980 runs, 800 revisions 126 KiB, 1,400 runs, 800 revisions

Word and character granularity are faster than 0.16.4 on the issue's documents. Run granularity, the default, stays
2.5 to 3 times 0.16.4 on paragraphs and 4.2 times on the table: see finding 2.

Findings in no issue

  1. A guard refusal that is likely false, kept on purpose. v0.17.0 refuses a comparison whenever a drawing shares
    its run with the begin mark of a complex field, whatever else changes: "comparison could not correlate split field
    run 2", or "comparison could not correlate paragraph run owner 2: 1 physical runs from cursor 6, 6 available". The
    first read of the guard, on the source-faithful model, passes. The second, project_source_body on the cleaned
    clone, runs after normalize_drawing_relationships has set docPr ids to 0 and rewritten r:embed to a
    signature, so field_source_run_fragments_at sees the outside run differ from the parsed one and the correlation
    fails. On a probe of 792 cases, 90 go from refused to accepted when the second read is skipped, with sound output
    (accept and reject round trip, no analysis id leaked, embeds resolve). 0.16.4 accepted 90 of the 108 inputs with
    this construct. This pull request keeps the refusal and pins it in
    issue446_comparison_keeps_refusing_a_drawing_in_a_field_begin_run, since a speed change must not decide which
    inputs a guard refuses.
  2. What run granularity still costs. A release profile of the issue's script at run granularity (400 paragraphs, macOS sample)
    attributes 24 % of a comparison to validate_footnote_custody in a document with no note (note_markers 16 %,
    footnote_reference_sites 9 %), 18.5 % to canonicalize_drawing_ids in a document with no drawing, 19 % to the
    package guard (normalized_package, including the second read this pull request keeps) and 15 % to
    compare_body. The custody work belongs to the pull request on compare fails when a footnote is added or removed #430, which changes that engine.
    canonicalize_drawing_ids also renumbers relationship ids read from the serialized opaque stories and sorts header
    and footer references, so "the model holds no drawing" is not a proof that it has nothing to do, and it was left
    as it is. Restoring the guard's second read cost about 3.5 % at run granularity on the issue's script: against
    v0.17.0 the first version of this branch, which skipped that read, measured 0.67 in the review and this one 0.70.
  3. Text boxes and field results on a resplit. One run against three with the same text and formatting gives 2
    revisions (a whole-shape replacement) in a VML text box at every granularity, and refuses with "comparison
    acceptance does not reproduce the edited stories" in a DrawingML text box, a complex field result and a simple
    field result, on v0.17.0 and on this branch. 0.16.4 gave 0 revisions for both field results and refused both text
    boxes ("comparison correlated 1 of 2 physical paragraph runs").
  4. A whole-run formatting change inside a hyperlink, a bookmarked paragraph or an inline control gives 0 revisions
    at run granularity
    , since 0.16.4: accepting the redline does not reproduce the edited formatting.
  5. accept_all can leave an empty w:rPr that a later comparison reads as a formatting change, so comparing an
    accepted redline with its edited input is not always empty (since 0.16.4).
  6. Character granularity aligns with a full LCS table. align is O(N x M) in time and memory per shell segment,
    so one long paragraph costs the square of its characters at character granularity: growth for 4 times the runs is
    6.2 on 0.16.4 and 7.7 on this branch. A common prefix and suffix trim before the table would make one edit
    linear. It is left for a change of its own.
  7. Per-leaf reads remain in the text-box projection (restore_resolved_leaf_occurrences), where text boxes are
    small. They were left as they are.

Gates run locally

On the final commit, macOS arm64, Rust 1.97.1, one suite at a time. Poppler 26.10 through pixi exec -s poppler
(CI pins 26.01), LibreOffice 26.8 (CI pins 26.2.5.2), no hb-subset 14.4.0.

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features -- -D warnings,
    scripts/prose_check.py, scripts/sync_agent_skills.py --check: clean.
  • scripts/hash_harness.py --check: 49 entries match. scripts/readme_doctests.py: pass, with the rdocx archive row
    re-recorded in the last commit.
  • cargo check --locked --target wasm32-unknown-unknown -p rdocx-wasm -p rpptx-wasm: pass.
  • cargo test -p rdocx (RUST_MIN_STACK=8388608, after cargo build -p rdocx-cli):
    • lib: 1053 passed, 3 failed, 13 ignored. The 3 are version pins of this machine:
      large_word_and_presentation_pdfs_preserve_logical_reading_order (pdftotext 26.01.0),
      word_and_powerpoint_chart_pixels_are_identical (at the rasterizer version assert),
      fx195_variable_svg_paint_matches_independent_static_instances (hb-subset 14.4.0 absent).
    • integration: 557 passed, 5 failed, 8 ignored. The 5 are the LibreOffice pins and the offline build:
      section_page_semantics_match_pinned_libreoffice_render, every_conditional_table_region_matches_word,
      odt_reader_matches_pinned_libreoffice_structure,
      sanitized_public_authoring_fixture_passes_every_conformance_stage,
      public_authored_theme_and_fonts_match_pinned_word_resolution.
    • regression: 2537 passed, 0 failed, 7 ignored. Doc tests: 2 passed.
  • cargo test -p rdocx-cli: 4 and 116 passed.
  • Python, CI-style debug build (opt-level 2, debug assertions and overflow checks), pytest crates/rdocx-py/tests:
    1400 passed, 61 failed, 2 skipped. 3 failures are version pins (test_issue_253_pdf_text_view on pdftotext,
    test_colour_inputs_and_nested_font_formats_reach_actual_rendering on pdftoppm,
    test_fx200_python_style_saved_output_paints_exact_expected_colours_with_deterministic_native_cli without
    RDOCX_CLI). 58 are in test_rendering_threads.py: 1 at the pdfinfo 26.01.0 pin and 57 on the missing
    F_X195_* inputs that the CI step "Prepare independent font acceptance inputs" builds with hb-subset.
  • mypy --strict crates/rdocx-py/tests/typing_smoke.py crates/rdocx-py/python/rdocx and mypy.stubtest rdocx on a
    release wheel (mypy 2.3.0, Python 3.12): no issues.

…ularity

Since v0.17.0 a word comparison aligns logical words over characters, so
that a word split across runs compares equal (F-X279b, issue 434 case 3).
The character units then reached the output as they were: every unchanged
character of a changed paragraph became its own w:r, and each letter of a
revision its own w:delText or w:t inside the revision's run. For the 200
paragraphs of issue 446 case 1 that is 17,180 runs and 517 KiB of
document.xml where v0.16.4 wrote 6,200 runs and 245 KiB. Character
granularity has always written one run per character, and v0.16.4 wrote
one run per word, space and punctuation mark at word granularity.

The granularity now sets what is compared, never how the result is cut.
Two rules, in the two helpers that the paragraph path and the inline
control path share, apply to every granularity, story and revision kind:

- coalesced_granular_alignment keeps unchanged pairs together while they
  continue the same original and the same edited text element, as it
  already kept the pairs of one change together. Unchanged text is one run
  between two revisions.
- merge_unit_runs joins consecutive fragments of one text element back
  into one text with one source selection, whole again when every fragment
  is there. A revision holds its text in one w:delText or w:t, and a fully
  unchanged element is published from its source as at run granularity.

The same 200 paragraphs now give 600 runs and 76 KiB, one run per revision
and one per stretch of text around them. Two cases still cut a stretch:
under ignore_whitespace an ignored whitespace unit ends it, so unchanged
text stays one run per word and per space, and a tab or a break ends it as
it ends a text element. The alignment, the text
revisions, the logical-word rule, the shared revision of a word split
across runs, the custody markers and the refusals are unchanged. One
visible difference besides the runs: a formatting change of a run is one
w:rPrChange per unchanged stretch, as at run granularity, instead of one
per word (v0.16.4) or per character (v0.17.0).

The space-flag control of compare_producer_noise pinned the one-run space
of the old shape. It now checks the same fact on the stretch that ends
with the space.

Part of tensorbee#446.

Tests, issue446_* in regression_test.rs state the shape as invariants in
the body, a table cell, an inline control, a hyperlink, a header and a
footnote (one text element a run, no added run that repeats the properties
of the sibling it follows, run count bounded by the revisions, run count
and added size independent of the unchanged text), two unit tests in
comparison.rs, test_issue446_* in test_core.py
Harness, unchanged, the samples make no comparison
…candidate once

A comparison became slower in v0.17.0 at every granularity, the default
run granularity included (about 4 times on the documents of issue 446,
with the same output), and quadratic in the children of one paragraph or
table. Four causes, none of them in the alignment:

- The source guard of F-X272 (af99e9d) read a parent from its start
  once per child. RunSource::capture did it for each run of a paragraph,
  publication_parent_at and source_child for each row of a table, cell of
  a row, child of a cell or a control and inline control of a paragraph,
  in the five source snapshots of a comparison and again in the compare
  and mark paths (compare_table, compare_row, compare_cell_from_xml,
  compare_granular_controls, compare_complex_paragraph,
  paragraph_children_xml, marked rows and cells, and the parent of each
  written piece in compare_granular_paragraph). capture_all,
  publication_parents_at and source_children read a parent once for all
  its children. Each answer, an error included, is the one a read for
  that child alone gives, and each is taken where that read was made, so
  the errors keep their order. ParentScopes reads the scopes a paragraph
  path may ask on its first question.
- Each postcondition direction resolved the candidate twice, once for the
  package guard and once more inside verify_footnote_destination
  (F-X272a, 1c69b7e). resolved_candidate resolves it once and both
  checks read it.
- The postcondition signature of an ordinary part is taken at character
  granularity so that run splits do not change it (F-X279b, 2d38731).
  It built one unit, one copy of the run properties and one token per
  character of all four documents. A run with no raw child and no deleted
  text is now read one stretch at a time, and consecutive plain characters
  are one token, in paragraphs and in the direct runs of a control. Two
  signatures read equal exactly when their character tokens did.
- A paragraph snapshot computed its run spans twice. It computes them
  once.

The package guard still reads each cleaned story a second time, as
v0.17.0 does. That read refuses a drawing that shares its run with the
begin mark of a complex field, whatever else changes ("comparison could
not correlate split field run 2"), and a test pins that refusal: a speed
change must not change which inputs a guard refuses.

compare() CPU time, median of 5 runs alternated between builds, release
wheels (0.16.4 and v0.17.0 from PyPI with fat LTO, this branch with LTO
off and 16 codegen units, which favours the older wheels), measured on
the final tree of this series:

    case                       granularity  0.16.4  v0.17.0  branch
    issue 446, 200 changed     run          0.11 s   0.44 s  0.31 s
    issue 446, 200 changed     word         0.64 s   6.65 s  0.45 s
    issue 446, 200 changed     character    1.74 s   6.95 s  0.76 s
    issue 446, 400 changed     run          0.21 s   0.89 s  0.62 s
    issue 446, 400 changed     word         1.38 s  14.40 s  0.94 s
    1000 paragraphs, 100 chg.  run          0.33 s   1.14 s  0.81 s
    1000 paragraphs, 100 chg.  word         0.73 s   4.33 s  0.94 s
    1000 paragraphs, 100 chg.  character    1.57 s   4.62 s  1.01 s
    one paragraph of 400 runs  run          0.06 s   0.53 s  0.12 s
    one paragraph of 400 runs  word         0.09 s   9.29 s  0.15 s
    table of 100 rows          run          0.21 s   1.74 s  0.88 s
    table of 100 rows          word         0.33 s   2.34 s  0.95 s

Growth for 4 times the rows of a table is 4.2 (0.16.4 4.2, v0.17.0 6.9)
and for 4 times the runs of one paragraph 4.4 at run and 4.6 at word
granularity (v0.17.0 13.2 at run).

Run granularity stays 2.5 to 3 times 0.16.4 on paragraphs and 4.2 on a
table. Restoring the guard's second read accounts for part of it. A
release profile of the issue 446 script at run granularity (400
paragraphs) attributes 24 percent of a comparison to the footnote custody
validation in a document with no note, 18.5 percent to
canonicalize_drawing_ids in a document with no drawing, 19 percent to the
package guard and 15 percent to compare_body.

Checked on the final tree of this series against the v0.17.0 release
wheel, with a debug build and every debug oracle on. The 1,080 cases of a
refusal map around revisions, notes, comments, moves, controls, fields and
bookmarks give the same refusals and messages and leave refused inputs
intact. 792 guard cases give the same refusals, messages and
run-granularity bytes. 500 random pairs give the same accepted and
rejected text and formatting, and the same insertions, deletions and run
bytes except 3 pure resplits inside an inline control, which a later
commit of this series compares as equal.

Part of tensorbee#446.

Tests, comparison.rs units compare the one-read answers with lone reads,
errors included, check the stretch tokens, and count the source bytes a
comparison reads for few and many runs, rows, hyperlink runs and
inserted paragraphs and tables at the three granularities,
issue446_comparison_keeps_refusing_a_drawing_in_a_field_begin_run in
regression_test.rs, no timing threshold
Harness, unchanged, the samples make no comparison
A word or character comparison of a changed paragraph whose w:t holds a
reference refused with "split text has opaque mixed events", in the body
and in every related story. That covers &, <, > and ",
which rdocx writes itself on save, and numeric references such as
&tensorbee#233;: saving and reopening "Smith & Sons pay now." and comparing it
with "... later." refused. 0.16.4 compared it.

source_text_fragment (F-X272, af99e9d) checks that the source of a
split text is one element holding text, and took exactly one text event.
The XML reader reports a reference as an event of its own between two
pieces of text. Any number of text and reference events now pass at the
text's depth. A nested element, CDATA, a comment or a processing
instruction still refuses. The value written comes from the parsed model
and is escaped again on output, as before.

Part of tensorbee#446.

Tests, issue446_comparison_splits_text_that_holds_references in
regression_test.rs, with the reference in the changed token, at word and
character granularity, in the body and a header, accepted and rejected
back to each input
Harness, unchanged, the samples make no comparison
A paragraph whose runs only split the same text differently compares
equal since v0.17.0 (F-X279b). An inline content control did not: its
runs were aligned one by one, so one run against three with the same text
and formatting gave 4 revisions at run granularity, as in 0.16.4. A word
redline of one sentence inside a control, accepted or rejected and
compared again with its input, gave 25 revisions at word granularity and
70 at character granularity on 0.16.4 and v0.17.0, and 4 and 8 before
this commit. It now gives none.

When every child of both controls is a run and the runs differ,
compare_control_from_xml now reads them with the equality the paragraph
path trusts, coalesced_paragraphs_equal, and keeps the original source
when they are equal. It does not apply under leaf capture, to a control
holding a raw child or a revision, or to runs holding a field, whose
source facts it cannot read from copies, which keep the path below.

Part of tensorbee#446.

Tests, issue446_comparison_reads_a_resplit_inline_control_as_equal in
regression_test.rs at the three granularities, with a real change kept as
a revision
Harness, unchanged, the samples make no comparison
The rdocx archive grows with the issue 446 comparison changes and their
tests, on main eb980e9. It is the only crate whose member bytes change.
It was measured on 2026-11-16, which its row and the remeasurement date
now record.

Tests, scripts/readme_doctests.py build_package_archive and
archive_measurement for rdocx, member bytes stable on a second pass
Harness, unchanged, measurements only

This branch has not been deployed

No deployments
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.

1 participant