Skip to content

Drop float records the layout has already buried (v6) - #819

Merged
gravitypdf-bot merged 1 commit into
gravitypdf-v6from
perf/prune-dead-float-divs-v6
Oct 26, 2026
Merged

gravitypdf-bot merged 1 commit into
gravitypdf-v6from
perf/prune-dead-float-divs-v6

Conversation

@gravitypdf-bot

Copy link
Copy Markdown

Summary

Brings the float pruning from #9 to gravitypdf-v6, the branch Gravity PDF 6.x bundles. It's upstream mpdf/mpdf development (a981bb7) with Gravity PDF's fixes on top. Without it, PDF for GravityView 2.0.0 directory PDFs slow down quadratically on Gravity PDF 6.18, because PDF for GravityView stops pruning floats itself there (GravityPDF/gravity-pdf#1951).

Try it

Write a few hundred cleared rows of three floated <div>s, one WriteHTML() call per row, and check $mpdf->floatDivs stays at 3 records instead of growing with every row.

Test plan

  • vendor/bin/phpunit tests/Mpdf/FloatDivTest.php passes (13 tests) on PHP 8.5
  • CI
More info

🤖 Generated with AI

$floatDivs is a document-global list of every float the document has
closed. It was emptied only in the constructor, yet GetFloatDivInfo()
reads all of it every time a float is placed, so a long document of
floated rows degrades to O(n^2) — 1000 rows of a 9-column float grid
took 34s, against 2.6s once the list stays bounded.

Route both float records through addFloatDiv(), which first drops the
records that ended at or above where the incoming float starts. Those
can no longer satisfy GetFloatDivInfo()'s `$currpos < $f['endpos']`
test, because layout only moves forward from there. Pruning is scoped
to the incoming float's own block formatting context, since ClearFloats
matches on blockContext alone and ignores position.

The comparison is against the incoming float's start rather than the
current cursor because the cursor rewinds to the top of the float just
written; a backwards jump then prunes nothing rather than pruning
wrongly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@gravitypdf-bot
gravitypdf-bot merged commit 502e48b into gravitypdf-v6 Oct 26, 2026
@gravitypdf-bot
gravitypdf-bot deleted the perf/prune-dead-float-divs-v6 branch October 26, 2026 04:41
gravitypdf-bot added a commit to GravityPDF/gravity-pdf that referenced this pull request Oct 26, 2026
…hing it

GravityPDF/mpdf's gravitypdf-v6 branch is upstream mPDF's development HEAD (a981bb7b) plus the float pruning
(GravityPDF/mpdf#819, from #9) and the Cache fix for writable directories is_writable() calls read-only
(GravityPDF/mpdf#820, #708). Composer installs it from there, so the php-scoper patchers that applied both fixes
while prefixing are gone, and a future mPDF update brings them along instead of failing the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakejackson1 jakejackson1 added the bug Something isn't working label Oct 26, 2026
@gravitypdf-bot gravitypdf-bot mentioned this pull request Oct 26, 2026
2 tasks
gravitypdf-bot added a commit to GravityPDF/gravity-pdf that referenced this pull request Oct 26, 2026
… floats

mPDF keeps every float it has closed in a document-wide list and rescans all of it each time it places a float, so a
long layout of floated rows slows down quadratically. PDF for GravityView 2.0.0 stops pruning that list itself on
Gravity PDF 6.18, because it expects 6.18 to bundle the fork's fix (GravityPDF/mpdf#9), but 6.18 bundled upstream
mPDF. A 1,000-row directory PDF took 7.8 s instead of 1.9 s.

GravityPDF/mpdf's gravitypdf-v6 branch is upstream mPDF's development HEAD (a981bb7b) plus the float pruning
(GravityPDF/mpdf#819, from #9) and the Cache fix for writable directories is_writable() calls read-only
(GravityPDF/mpdf#820, #708). Composer installs it from there, so the php-scoper patcher for the Cache fix is gone, and
a future mPDF update brings both fixes along instead of failing the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gravitypdf-bot added a commit to GravityPDF/gravity-pdf that referenced this pull request Oct 26, 2026
… floats

mPDF keeps every float it has closed in a document-wide list and rescans all of it each time it places a float, so a
long layout of floated rows slows down quadratically. PDF for GravityView 2.0.0 stops pruning that list itself on
Gravity PDF 6.18, because it expects 6.18 to bundle the fork's fix (GravityPDF/mpdf#9), but 6.18 bundled upstream
mPDF. A 1,000-row directory PDF took 7.8 s instead of 1.9 s.

GravityPDF/mpdf's gravitypdf-v6 branch is upstream mPDF's development HEAD (a981bb7b) plus the float pruning
(GravityPDF/mpdf#819, from #9) and the Cache fix for writable directories is_writable() calls read-only
(GravityPDF/mpdf#820, #708). Composer installs it from there, so the php-scoper patcher for the Cache fix is gone, and
a future mPDF update brings both fixes along instead of failing the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gravitypdf-bot added a commit to GravityPDF/gravity-pdf that referenced this pull request Oct 26, 2026
… floats (#1951)

mPDF keeps every float it has closed in a document-wide list and rescans all of it each time it places a float, so a
long layout of floated rows slows down quadratically. PDF for GravityView 2.0.0 stops pruning that list itself on
Gravity PDF 6.18, because it expects 6.18 to bundle the fork's fix (GravityPDF/mpdf#9), but 6.18 bundled upstream
mPDF. A 1,000-row directory PDF took 7.8 s instead of 1.9 s.

GravityPDF/mpdf's gravitypdf-v6 branch is upstream mPDF's development HEAD (a981bb7b) plus the float pruning
(GravityPDF/mpdf#819, from #9) and the Cache fix for writable directories is_writable() calls read-only
(GravityPDF/mpdf#820, #708). Composer installs it from there, so the php-scoper patcher for the Cache fix is gone, and
a future mPDF update brings both fixes along instead of failing the build.

Co-authored-by: gravitypdf-bot <support@gravitypdf.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants