New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better performance #384

merged 12 commits into from Nov 10, 2016


None yet
1 participant
Copy link

liZe commented Nov 3, 2016

The main point of this pull request is to make StyleDict inherit from dict instead of the copy-on-write-like strategy used before.

This change really improves the speed (yeah, profiling helps), but unfortunately has a high memory footprint. That's why memory usage has been also improved, including an impressive don't-store-the-dummy-cairo-context-in-the-layout-forever in 152193c (already incluled in the font-face branch).

The commits are small and hopefully easy to understand and to revert if needed. I've got exactly the same PDFs before and after these commits with many examples, but I'm sure that bugs have been introduced.

Here are the results (with reliable science inside):

Offline HTML5 Specification

Long document with a lot of lists and underlined links.


  • 6.0s
  • 146MB memory peak


  • 6.3s (+5%)
  • 130MB memory peak (-11%)

font-face + perf:

  • 4.5s (-25%)
  • 159MB memory peak (+9%)

Offline Alice Adventures in Wonderland

Long document with repetitive justified text.


  • 12.5s
  • 162MB memory peak


  • 9.8s (-21%)
  • 134MB memory peak (-17%)

font-face + perf:

  • 7.1s (-43%, too good to be true)
  • 161MB memory peak (=)

Online WeasyPrint

Simple website, uses online fonts (that's why it's slower now).


  • 1.6s
  • 66MB memory peak


  • 2.2s (+38%)
  • 68MB memory peak (+3%)

font-face + perf:

  • 2.0s (+25%)
  • 70MB memory peak (+6%)

Online Wikipedia

Printable version of a Wikipedia page, long left-aligned paragraphs with floats.


  • 7.9s
  • 134MB memory peak


  • 8.2s (+4%)
  • 124MB memory peak (-7%)

font-face + perf:

  • 6.6s (-16%)
  • 141MB memory peak (+5%)

liZe added some commits Nov 1, 2016

Change StyleDict into a real dict
This commit has a really good impact on speed (+15~30%) but a really bad
impact on memory usage (+30~40%).
Don't store dummy context in Layout
This has an amazing results on memory: -15% when rendering the first page
of the HTML5 spec.
Don't split again the text box with justified text
Instead of using split_text_box, we can only call the faster
split_first_line instead.

This commit also copies the style before updating the word spacing,
avoiding a bug introduced in this branch now that the style is shared
across the lines.

@liZe liZe changed the title Better performances Better performance Nov 3, 2016

@liZe liZe added the feature label Nov 3, 2016

@liZe liZe added this to the v0.32 milestone Nov 3, 2016

liZe added some commits Nov 5, 2016

Don't unref attribute lists for text features
Tried many times at many places of the code, it always segfaults. Keep
them for now.

This comment has been minimized.

Copy link

liZe commented Nov 10, 2016

I've fixed most of the memory leaks, there's no crash with the W3C test suites anymore, let's merge.

@liZe liZe merged commit 588756d into master Nov 10, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@liZe liZe deleted the perf branch Nov 10, 2016

jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Jan 15, 2017

Update py-weasyprint to 0.34.
Version 0.34

Released on 2016-12-21.

Bug fixes:

* `#398 <>`_:
  Honor the presentational_hints option for PDFs.
* `#399 <>`_:
  Avoid CairoSVG-2.0.0rc* on Python 2.
* `#396 <>`_:
  Correctly close files open by mkstemp.
* `#403 <>`_:
  Cast the number of columns into int.
* Fix multi-page multi-columns and add related tests.

Version 0.33

Released on 2016-11-28.

New features:

* `#393 <>`_:
  Add tests on MacOS.
* `#370 <>`_:
  Enable @font-face on MacOS.

Bug fixes:

* `#389 <>`_:
  Always update resume_at when splitting lines.
* `#394 <>`_:
  Don't build universal wheels.
* `#388 <>`_:
  Fix logic when finishing block formatting context.

Version 0.32

Released on 2016-11-17.

New features:

* `#28 <>`_:
  Support @font-face on Linux.
* Support CSS fonts level 3 almost entirely, including OpenType features.
* `#253 <>`_:
  Support presentational hints (optional).
* Support break-after, break-before and break-inside for pages and columns.
* `#384 <>`_:
  Major performance boost.

Bux fixes:

* `#368 <>`_:
  Respect white-space for shrink-to-fit.
* `#382 <>`_:
  Fix the preferred width for column groups.
* Handle relative boxes in column-layout boxes.


* Add more and more documentation about Windows installation.
* `#355 <>`_:
  Add fonts requirements for tests.

Version 0.31

Released on 2016-08-28.

New features:

* `#124 <>`_:
  Add MIME sniffing for images.
* `#60 <>`_:
  CSS Multi-column Layout.
* `#197 <>`_:
  Add hyphens at line breaks activated by a soft hyphen.

Bux fixes:

* `#132 <>`_:
  Fix Python 3 compatibility on Windows.


* `#329 <>`_:
  Add documentation about installation on Windows.

Version 0.30

Released on 2016-07-18.

WeasyPrint now depends on html5lib-0.999999999.

Bux fixes:

* Fix Acid2
* `#325 <>`_:
  Cutting lines is broken in page margin boxes.
* `#334 <>`_:
  Newest html5lib 0.999999999 breaks rendering.

Version 0.29

Released on 2016-06-17.

Bug fixes:

* `#263 <>`_:
  Don't crash with floats with percents in positions.
* `#323 <>`_:
  Fix CairoSVG 2.0 pre-release dependency in Python 2.x.

Version 0.28

Released on 2016-05-16.

Bug fixes:

* `#189 <>`_:
  ``white-space: nowrap`` still wraps on hyphens
* `#305 <>`_:
  Fix crashes on some tables
* Don't crash when transform matrix isn't invertible
* Don't crash when rendering ratio-only SVG images
* Fix margins and borders on some tables

Version 0.27

Released on 2016-04-08.

New features:

* `#295 <>`_:
  Support the 'rem' unit.
* `#299 <>`_:
  Enhance the support of SVG images.

Bug fixes:

* `#307 <>`_:
  Fix the layout of cells larger than their tables.


* The website is now on GitHub Pages, the documentation is on Read the Docs.
* `#297 <>`_:
  Rewrite the CSS chapter of the documentation.

@liZe liZe referenced this pull request Jul 22, 2017


Profile big tables #70

@liZe liZe referenced this pull request Feb 21, 2018


Perfomance on large pdf #545

@xmo-odoo xmo-odoo referenced this pull request Aug 16, 2018


Move bits to native code? #670

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment