Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cache intermediate results for intrinsic widths on tables.

This fixes huges performance problems when a large table is split
across many pages.
  • Loading branch information...
commit 0ff73c49bc26ac3dc087a433f1d570c76b3efc12 1 parent 9834ccb
@SimonSapin SimonSapin authored
Showing with 11 additions and 1 deletion.
  1. +11 −1 weasyprint/layout/preferred.py
View
12 weasyprint/layout/preferred.py
@@ -12,6 +12,8 @@
from __future__ import division, unicode_literals
+import weakref
+
from ..formatting_structure import boxes
from .. import text
@@ -204,6 +206,8 @@ def inline_preferred_width(context, box, outer=True):
return adjust(box, outer, widest_line)
+TABLE_CACHE = weakref.WeakKeyDictionary()
+
def table_and_columns_preferred_widths(context, box, outer=True,
resolved_table_width=False):
"""Return preferred widths for the table and its columns.
@@ -217,6 +221,10 @@ def table_and_columns_preferred_widths(context, box, outer=True,
"""
table = box.get_wrapped_table()
+ result = TABLE_CACHE.get(table)
+ if result:
+ return result
+
if table.style.border_collapse == 'separate':
border_spacing_x, _ = table.style.border_spacing
else:
@@ -370,9 +378,11 @@ def table_and_columns_preferred_widths(context, box, outer=True,
if table_preferred_minimum_width > table_preferred_width:
table_preferred_width = table_preferred_minimum_width
- return (
+ result = (
table_preferred_minimum_width, table_preferred_width,
column_preferred_minimum_widths, column_preferred_widths)
+ TABLE_CACHE[table] = result
+ return result
def table_preferred_minimum_width(context, box, outer=True):
Please sign in to comment.
Something went wrong with that request. Please try again.