CourtBouillon

Authentic people growing open source code with taste

WeasyPrint v55: Beta Time

WeasyPrint v55 is the next major version of WeasyPrint. We released a beta, you can give it a try and help us to have a nice stable major release! For this version, the main focus was performance improvement. Let’s see what we got in this version!

Better performance

The main goal of this version is to improve WeasyPrint’s performance 🌱.

For that, changes have been done in WeasyPrint on fonts management, on column layout and in cssselect2.

Fonts

When a font is included into the PDF, only the needed information of the font is now kept, which means font objects are now smaller.

Most of the work for text is done with Harfbuzz and Pango libraries. Calls to these librairies have been reduced, improving the font treatment speed. This improvement is particulary useful for large documents always using a same @font-face.

Another improvement for font management is related to the ch and ex units, whose absolute sizes are now cached. With this enhancement, rendering large documents using these units a lot is now really faster.

Column layout

The column layout algorithm has been changed 🤓.

A massive performance improvement is visible when you have columns split among multiple pages: instead of slowly increasing the column height, WeasyPrint now directly uses all the available height when the content doesn’t fit in the page.

If you generate long documents with columns, you should give this new version a try!

cssselect2

The main change in cssselect2 new version is about how ancestors are calculated for each HTML element 🧓.

When a CSS selector composed with a space is encountered on an HTML element, we need to get all its ancestors. Before, we used to go through the whole tree to get all of them, multiple times. Now, the element’s ancestors are directly cached when needed to avoid useless calculation.

The same improvement has been included to cache previous siblings, used in the :nth-child selector (among others).

Performance graphs

To illustrate these performance improvement, let’s have a look at the following graphs (everybody likes graphs 📊, don’t you?)

You can find the documents used for these on the WeasyPerf page.

Memory and time used for the PDF generation and PDF size comparison between WeasyPrint v54.3 and v55.0 beta on a document with columns.
Memory and time used for the PDF generation and PDF size comparison between WeasyPrint v54.3 and v55.0 beta on a document using many fonts.
Memory and time used for the PDF generation and PDF size comparison between WeasyPrint v54.3 and v55.0 beta on a documentation page.

For these documents, memory and time used during the PDF generation have been improved, and the size of the generated PDF got down. That’s also the case for most of the documents we tested.

These results are nice to have an indication on how the different improvements are efficient. But to have the results related to your documents, trying the beta is the best solution 😉!

And More…

Besides performance improvements, new features and bug fixes come in this version 🎉!

Thanks a lot to our wonderful contributors (and especially to aschmitz) for their hard work on this release. Performance improvements can be tricky 💜.

What Are the Next Steps?

The next step is yours! Don’t hesitate to try this beta and report bugs you may find 🐞.

The one after is to fix the reported bugs and release a nice WeasyPrint version 55.

Have fun with this beta 💜.