Skip to content

fix(layout): lay a list out from the items it holds in this save - #697

Merged
Tim81 merged 6 commits into
mainfrom
fix/list-lays-out-current
Nov 26, 2026
Merged

Tim81 merged 6 commits into
mainfrom
fix/list-lays-out-current

Conversation

@Tim81

@Tim81 Tim81 commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #691

Summary

A ListRenderer now lays a list out from the items it holds in the save that lays it out.
Before, it built a list's entries at its first layout, at that layout's width, and kept them for
every later one, whatever that layout was: another save, another document, a layout of yours
before the save, a renderer of yours that held the list. A paragraph that answers Nothing keeps
where its last layout put its lines, and Draw reads that, so a reused renderer drew an entry's
lines from an earlier document at a place where its layout now placed nothing (#691).

The rule, stated once on ListRenderer.Layout, with its one exception: the entries are built for each
save and each kind of call (the document's own calls, and the calls a renderer of yours makes), from
the items the list holds then, at the width of the first layout of that kind in that save. A piece a
split returned keeps the entries of the layout that made it and never rebuilds, as on 251adf8; two
rows pin that (APieceOfALayoutMadeOutsideAnySave_..., APieceACallerKeepsAcrossSaves_...).
A rebuild replaces the entries and the counts that belong to them. A child whose layout answers
Nothing draws nothing. The other docs and the CHANGELOG point to the rule.

  • The entries of a build are one object (Built) that holds the save number, not the run, so a
    reused renderer no longer keeps the first document alive.
  • The twin has two instances, one for the document's calls and one for a renderer of yours that
    holds the list, so each kind reads its own entries and its own placement state.
  • A context a renderer of yours kept from an earlier save carries that save's number
    (ContinuationSession.Save) and is a renderer's call in the next one.
  • ListRenderer.Draw calls the new ParagraphRenderer.ClearPlacement when a marker or text
    answers Nothing there.

Removed: _earlier, AdoptEarlier, WithoutClamp, Entry.UnclampedGutter, BuiltByAnEarlierLayout,
_builtUnder, _builtForCaller and the Held route reached only through history. Kept:
IsCalledByDocument (it now decides the kind of call), _placementInherited, the twin for a context
the document did not address, the whole-as-main twin and its placement restore, drawability, the
clamped-marker guard and the continuation-limit twin. src is +212/-223 lines against 251adf8.

Rulings applied

  • A reused list refuses as a new one does. 33,024 documents of the 103,200-document matrix save on
    251adf8 and are refused now (24,768 after an item in an undefined Standard14 value was added,
    8,256 after a child was added to an item of a list whose indent leaves its text no width, which a
    new list of that shape is refused with on 2.3.3 too); a new renderer is refused identically in each.
  • A document refused only because of entries the list never built saves. An anchored item added
    since is placed (ListReuseTests.AnAnchoredItemAddedSinceTheLastSave_isPlacedInTheNextOne).

Measured against 251adf8

Per-kind oracle: the same document built with one new renderer for each kind of call, nothing laid
out before it, on the build under test.

Set Documents Against 251adf8 Against the per-kind oracle
Earlier-layout generator 200,000 137,226 bytes differ, 1,116 equal bytes with other diagnostics, 60,493 equal, 1,165 refused by both; no status change 200,000 equal (1,165 refused identically)
Slots generator 80,000 44,942 identical, 34,338 bytes differ, 720 same status with other slot hashes or diagnostics; no status change 80,000 identical
Matrix of earlier layouts, changes, callers, widths 103,200 11,018 equal, 57,094 bytes differ, 2,064 refused by both, 33,024 save to refuse 103,200 equal (35,088 refused identically)
Four generators, each list renderer placed once 110,000 139 bytes differ, 9 refused to save, 0 save to refuse not applicable
Limit generator at 300 continuations 1,500 thresholds equal in 1,500; 20 differ in bytes at the threshold not applicable

Single-use documents. In the four generators each list renderer is placed once (most documents hold
several lists). With only the Nothing rule left out of the build, all 110,000 generated documents,
all 1,500 limit rows and the 2,304 matrix rows with no earlier layout that use one kind of call equal
251adf8, so no path where the twin took the list's own entries changes such a document in the sets
measured. The 139 and 20 byte differences and the saves below come from the Nothing rule alone:
lines of an earlier layout of the same save are no longer drawn (the mechanism of #691 inside one
save: two passes, a second placement, or a held and a direct use). Seven of the 139 also report fewer
encoding substitutions (601), because the stale line produced one. A document that uses both kinds of
call with one renderer reads two sets of entries, each at its first width, where 251adf8 read one;
that is the other source of byte differences in the matrix.

Documents that save now. In the four generators the class is an item in an undefined Standard14
value. 251adf8 threw
IndexOutOfRangeException because a paragraph that placed nothing drew an earlier layout's lines in
that font. It has 12 seeds across the generator runs reviewed: the 9 of the first runs (variant 3
seeds 7862, 10053, 10938, 24672, 29247, 29288; variant 4 seeds 16088, 19765, 24029, built at commit
1055f5d) and 3 from the review's new ranges (variant 3 seed 115412; variant 4 seeds 107718, 124710).
With the undefined value replaced by Helvetica, 251adf8 saves all 12 (review measurement). The
general class is wider than these seeds: any document refused only because a reused list renderer drew an
earlier layout's lines now saves as a new renderer's save does. A second review measured it with a
font handle from another document in an entry whose text has no width in the second document: 251adf8
refuses with ArgumentException in 16 of 16 rows, this branch and a new renderer on either build save. Maintainer
ruling: accepted and documented in the CHANGELOG. The saved files of the first 9 pass qpdf --check
(12.4.2), none claims a PDF/A or PDF/UA level so veraPDF does not apply, and each writes only defined
fonts (no /BaseFont for the undefined value). 3.0 refuses an undefined font value where it is set
(#696).

Row by row. All 139 single-use byte differences of the four generators and the 20 of the limit
generator were traced on 251adf8 and on a build of this branch that logs each placement it clears
(not committed). In every one, the new file draws a subset of what 251adf8 drew, per page stream and
position, adds nothing, and a cleared non-empty placement was logged: 251adf8 drew lines of an earlier
placement in the same save at a place where the marker or text answered Nothing. No row is another
kind of difference. The limit rows' traces reproduce the generator's hashes (40 of 40).

Residual cost. The entries are built for each save and each kind of call, and once more in a save that
places the list as its twin after it built them, so the cost is linear in the builds. net10.0 Release, 251adf8 against this branch (my runs, and the review's on a loaded
machine):

  • a list placed as its twin after the list built its entries (20,001 entries, one that no page
    holds): 246 to 247 MB before, 293 to 294 MB now; my runs showed about the same time, the
    review measured 693 to 786 ms before and 905 to 1,107 ms now;
  • one renderer placed directly and held by a wrapper in one save (20,000 entries): 197 MB and one
    build before, 258 MB and two builds now;
  • one renderer reused for five saves (20,000 entries): 417 MB and one build before, 726 MB and five
    builds now;
  • one renderer added twice: unchanged;
  • five other large-list cost cases kept from the earlier list work are unchanged (254, 236, 108, 99 and
    84 MB).

Other containers. A paragraph, a keep-together paragraph, a table, and a paragraph held by a wrapper
of yours, reused across two documents (120 documents each, page 200x100), draw the same bytes as a
new renderer on 251adf8, so nothing outside ListRenderer changed for the Nothing rule.

Removed in 3.0

The held twin (HeldTwin) and the two-instance split are 2.x compatibility devices, removed with the
twin in 3.0 (#688). ContinuationSession.Save and the save check in IsCalledByDocument go with
LayoutContext.Session (#688).

Mutations

Each mutant ran in a detached worktree of its own over the list test classes (net10.0).

Mutant Failing methods (examples)
the twin takes the list's own entries when it has none 11 (WhateverLaidTheListOutFirst_theDocumentLaysItOutFromWhatTheListHoldsNow, AReusedList_reportsTheFallbackOnlyWhereTheDocumentLaysEveryListOutAsItWas)
the held twin and the document twin are one instance 3 (AListLaidOutFromACallersDraw_andPlacedByTheDocument_readsEntriesForEachKindOfCall, WhateverLaidTheListOutFirst_...)
entries built once for each instance 18 (AChildTheFirstDocumentsClampNarrowed_getsTheGutterTheSecondWidthGives, ...)
a rebuild adds the counts of the build it replaces 5 (TheClampSkippedCount_belongsToEachSave, AReusedRenderer_givesTheOutcomeAFreshRendererGives)
a child whose layout answered Nothing is drawn, or only the marker 2 (OneRendererHeldTwice_drawsWhatARendererForEachPlacementDraws, ThePiecesOfAHeldList_reportNothingUnlessTheDocumentPlacesThem)
_placementInherited dropped 2 (ThePiecesOfAHeldList_reportNothingUnlessTheDocumentPlacesThem, ...)
placeability kept across rebuilds 5 (APageHeightThatChangesBetweenSaves_changesWhichEntriesNoPageHolds, ...)
the twin copies the entries no page holds from any save 1 (AnEntryNoPageHeldInTheFirstSave_isNotReportedWhereASecondSaveHoldsIt)
a context kept from an earlier save is the document's call 1 (AContextKeptFromAnEarlierSave_isACallersCallInTheNextOne)
pieces rebuild in another save 2 (APieceOfALayoutMadeOutsideAnySave_keepsItsEntriesAfterTheListChanged, APieceACallerKeepsAcrossSaves_keepsTheEntriesOfTheSaveThatMadeIt)

Tests flipped or deleted

Each pinned the entries or the stale lines of an earlier layout (#691). Old name to new name:

  • ListPlacementAdoptionTests:
    • AListLaidOutBeforeTheSave_keepsTheEntriesThatCallBuilt to ..._isClampedAsAFreshListIs
    • AListLaidOutBeforeTheSaveAtAnotherWidth_isDrawnFromTheEntriesThatCallBuilt to ..._isDrawnFromEntriesBuiltForTheSave
    • AListRendererReusedForASecondDocument_keepsTheEntriesTheFirstBuilt to ..._drawsWhatAFreshRendererDraws
    • AListRendererReusedForASecondDocument_keepsTheGutterTheFirstWidthGave to ..._getsTheGutterTheSecondWidthGives
    • AListChangedBetweenTwoDocuments_isDrawnFromTheEntriesTheFirstBuilt to ..._isDrawnFromTheItemsItHoldsNow
    • AListChangedAfterTheClampNarrowedAnEntry_keepsTheEntryAsTheFirstDocumentBuiltItWithoutTheClamp to ..._isLaidOutFromTheListAsItIs
    • AnEntryTheFirstDocumentsClampNarrowed_isNotHeldToTheClampsRuleInTheSecond to ..._isBuiltAsANewRendererBuildsItInTheSecond
    • AnEntryTheFirstDocumentsClampNarrowed_keepsItsLanguageInTheSecond to AReusedEntry_keepsItsLanguageInTheSecondDocument (premise reworded, still passes)
    • AReusedListInADocumentThatHoldsAnUndrawableEntry_reportsTheEntriesTheFirstClampNarrowed to ..._reportsTheEntriesTheClampWouldNarrowInThatSave
    • AReusedListWhoseKeptEntryUsesTheFirstDocumentsFont_... to AReusedListWhoseItemUsesTheFirstDocumentsFont_... (premise reworded, still passes)
    • AChildTheFirstDocumentsClampNarrowed_keepsItsGutterInTheSecond to ..._getsTheGutterTheSecondWidthGives
    • ARendererAddedAndThenHeldInOneDocument_laysTheHeldOneOutFromTheEntriesItBuilt to ..._laysTheHeldOneOutFromEntriesOfItsOwn
    • AListRendererReusedForASecondDocument_reportsNothingThere to ..._reportsWhatAFreshRendererReports
  • AListChangedAfterTheFirstDocument_addsNoGlyphToTheSecondDocumentsSubset: deleted;
    ListReuseTests.AListChangedAfterTheFirstSave_putsTheGlyphsAFreshRendererPutsInTheSubset replaces it,
    because an item added since is measured by a new build too.
  • ListEarlierLayoutTests: WhateverLaidTheListOutFirst_theDocumentKeepsTheEntriesThatLayoutBuilt to
    ..._theDocumentLaysItOutFromWhatTheListHoldsNow;
    AListHeldByACallersRendererAndThenAddedToTheDocument_isDrawnFromTheEntriesTheHeldLayoutBuilt to
    ..._isDrawnFromEntriesBuiltAtThePagesWidth; AReusedList_reportsTheFallbackOnlyWhere... keeps its
    name and now expects the clamp where the document does not keep every list as it was.

Gates

Release build 0 warnings. Layout.Tests 3,651 on each of net10.0 and net11.0 (2 skipped on each, 7,302
in all) and Barcodes.Tests 1,052 on each (2,104 in all), with REQUIRE_ORACLES and REQUIRE_VERAPDF, 0
failed. dotnet format --verify-no-changes, the clean-room check and generate-roadmap.py --check pass.

A ListRenderer built its entries at its first layout and kept them for
every later one, so a renderer reused for a second document drew the
lines an entry had in the first at a place where its layout in the
second placed nothing, and an item added since was never read.

The entries are now built from the items the list holds when a save
first lays it out, once for the document's own calls and once for the
calls a renderer of the caller's makes, and no other save or kind of
call reads them. A child whose layout answers Nothing draws nothing.
The adoption of earlier entries by the twin is removed.
…hangelog

ListRenderer.Layout states which items a layout reads; ListElement,
LayoutDiagnosticCode and Document.cs point to it or drop the sentences
that described earlier layouts. The changelog entry lists the output,
refusal and save changes with the documents they were measured on.
A document whose only refusal was a paragraph drawing an earlier
layout's lines in an undefined font now saves, and the file holds no
font resource for that value.
@Tim81 Tim81 added bug Something isn't working area/layout high-level document/layout engine labels Nov 26, 2026
A piece a split returned keeps the entries of the layout that made it
and never rebuilds, so the rule on ListRenderer.Layout says so and the
other docs point to it. Two rows pin the piece for a layout made outside
any save and for a piece a caller keeps across saves. The changelog
entry drops its figures, and no longer names a foreign font handle
among the documents that now save.
…691)

Layouts made outside any save share one build, so the sentence that no
save reads such a build was false; the rule now says what is shared and
points the piece and outside-save cases to #696, which removes layout
state, instead of #688. The CHANGELOG names the general class of saves
that were refused only through an earlier layout's lines, counts the
extra build of a list placed as its twin, and no longer says
LayoutDiagnosticCode points to the rule. Two test comments are
corrected.
#691)

The sentence on layouts made outside any save was false when a save in
between lays the list out through a renderer of yours. The remarks now
tell a caller not to rely on what such a layout reads, which 3.0 removes
with the layout state (#696). The CHANGELOG names the saved class for a
reused list renderer, the case that was measured.
@Tim81
Tim81 merged commit 5f79f4a into main Nov 26, 2026
4 checks passed
@Tim81
Tim81 deleted the fix/list-lays-out-current branch November 26, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/layout high-level document/layout engine bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A reused list renderer draws the lines its earlier layout placed

1 participant