Skip to content
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

Memory leak in version 63 #2319

Closed
MarouaneMan opened this issue Dec 3, 2024 · 3 comments
Closed

Memory leak in version 63 #2319

MarouaneMan opened this issue Dec 3, 2024 · 3 comments
Labels
performance Too slow renderings

Comments

@MarouaneMan
Copy link

MarouaneMan commented Dec 3, 2024

Hello 👋,

We've discovered that we have a high memory usage in one of our services, and after investigating, it seems that the latest version of weasyprint 63 consumes more memory than expected.

The example below consumes over 2GB using weasyprint 63.
Using version 62.3 it is stable at ~60MB.

Python 3.13.0

Thanks a lot !

python
import gc
import psutil
from weasyprint import HTML

iterations = 10000
for i in range(iterations):
    pdf = HTML(string="<html>Hello world</html>").write_pdf(
    '/tmp/example.pdf', stylesheets=[],
    font_config=None)

    progress = (i + 1) / iterations * 100
    process = psutil.Process()
    memory_info = process.memory_info()
    print(
        f"Progress: {progress:.2f}% | "
        f"Current Memory Usage: {memory_info.rss / (1024 * 1024):.2f} MB"
    )
    if i % 200 == 0:
        #gc.collect()
        pass
@liZe
Copy link
Member

liZe commented Dec 3, 2024

Thanks for the report. git bisect gives a culprit: 3e87175.

@liZe
Copy link
Member

liZe commented Dec 3, 2024

There’s even a second memory leak in 95d2c37.

liZe added a commit that referenced this issue Dec 3, 2024
The config has to be freed twice, because
pango_fc_font_map_set_config increases the number of references to it.

Related to #2319.
@liZe liZe closed this as completed in e4ed732 Dec 3, 2024
@liZe
Copy link
Member

liZe commented Dec 3, 2024

We’ve fixed multiple memory leaks, memory use is quite stable now. Feedback is welcome!

@liZe liZe added the performance Too slow renderings label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Too slow renderings
Projects
None yet
Development

No branches or pull requests

2 participants