Skip to content

Bundle mPDF from the fork's gravitypdf-v6 branch to fix slow float layouts (6.18.0) - #1951

Merged
gravitypdf-bot merged 1 commit into
hot-patch-6.18.0from
fix/mpdf-prune-buried-floats-6.18.0
Oct 26, 2026
Merged

gravitypdf-bot merged 1 commit into
hot-patch-6.18.0from
fix/mpdf-prune-buried-floats-6.18.0

Conversation

@zamoragregory

@zamoragregory zamoragregory commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

mPDF keeps every float it has closed in a document-wide list, and rescans the whole list 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 mPDF fork's fix (GravityPDF/mpdf#9). 6.18 bundles upstream mPDF instead, so neither side prunes, and long directory PDFs slow down: 1,000 rows take 7.8 s instead of 1.9 s. 6.18 now bundles mPDF from the fork's new gravitypdf-v6 branch, which is upstream mPDF's development HEAD plus Gravity PDF's fixes:

Try it

  1. Run composer install, then composer prefix.
  2. vendor_prefixed/mpdf/mpdf/src/Mpdf.php now has addFloatDiv(), and vendor_prefixed/mpdf/mpdf/src/Cache.php no longer calls is_writable().
  3. With PDF for GravityView 2.0.0, generate the directory PDF of a View with a few hundred entries in the Table layout. It's about as fast as with PDF for GravityView's own pruning on 6.17.2. Before this change it slowed down sharply as the View grew.

Test plan

  • yarn test:php -- --filter 'Test_Mpdf|Test_Cache'
  • The release zip's vendor_prefixed/mpdf/mpdf/src/Mpdf.php contains addFloatDiv()
More info
  • Benchmark (PHP 8.3), with rows of three floated cells streamed into one open container, as PDF for GravityView 2.0.0 writes a directory on 6.18 (its own pruning off):

    Rows RC1's mPDF This change RC1's mPDF with PDF for GravityView's own pruning
    250 0.85 s 0.48 s 0.48 s
    500 2.46 s 0.96 s 0.92 s
    1,000 7.76 s (3,000 float records kept) 1.92 s (3 kept) 1.84 s

    The page counts are the same in every case. The benchmark was taken with the earlier scoper-patch version of this PR, which applied the same code as Drop float records the layout has already buried (v6) mpdf#819.

  • gravitypdf-v6 is mpdf/mpdf development at a981bb7b (what RC1 locks) plus $this->data->template_fontdata_location no longer used #819 and Clear mPDF cache when font is deleted #820. mPDF's full suite (1,000 tests) passes on it on PHP 8.5, and the fork's CI (tests, snapshots, static analysis, coding standard) passes on the branch since Run CI on gravitypdf-v6 mpdf#821 turned it on.

  • The ServiceFactory patcher stays: it points mPDF at Gravity PDF's own Cache class.

  • Tests:

    • test_dropping_buried_floats_leaves_the_pages_unchanged writes 50 rows with and without pruning and compares the page content streams, as mpdf#9's own tests do.
    • test_floats_buried_by_a_new_float_are_dropped fails if the bundled mPDF doesn't prune: 150 float records instead of 3. That catches a later composer update that loses the fork's fix.
  • composer install/composer prefix haven't been run locally for the fork switch. This PR's CI builds and tests it.

  • On a test site with the earlier build's mPDF, PDF for GravityView 2.0.0's single and directory PDFs for six Views have the same page counts as on RC1. A directory PDF with signed shortcodes still signs all 16 row links.

  • This is for 6.18.0 only, with no development PR. development still locks upstream mpdf/mpdf and will move to the fork with 7.0.

  • Adds a CHANGELOG line, because it also speeds up any long float layout in a custom template.

🤖 Generated with AI

@jakejackson1
jakejackson1 marked this pull request as draft October 26, 2026 04:14
@gravitypdf-bot gravitypdf-bot changed the title Prune buried float records in the bundled mPDF (6.18.0) Bundle mPDF from the fork's gravitypdf-v6 branch for the float and cache fixes (6.18.0) Oct 26, 2026
@gravitypdf-bot
gravitypdf-bot force-pushed the fix/mpdf-prune-buried-floats-6.18.0 branch from 7aac3d3 to 09dd06a Compare October 26, 2026 05:28
@gravitypdf-bot gravitypdf-bot changed the title Bundle mPDF from the fork's gravitypdf-v6 branch for the float and cache fixes (6.18.0) Bundle mPDF from the fork's gravitypdf-v6 branch to fix slow float layouts (6.18.0) Oct 26, 2026
@jakejackson1
jakejackson1 marked this pull request as ready for review October 26, 2026 05:28
… 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
gravitypdf-bot force-pushed the fix/mpdf-prune-buried-floats-6.18.0 branch from 09dd06a to 508a9fd Compare October 26, 2026 05:30
@gravitypdf-bot
gravitypdf-bot merged commit 3bdacc7 into hot-patch-6.18.0 Oct 26, 2026
13 checks passed
@gravitypdf-bot
gravitypdf-bot deleted the fix/mpdf-prune-buried-floats-6.18.0 branch October 26, 2026 05:35
@gravitypdf-bot gravitypdf-bot mentioned this pull request Oct 26, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants