-
-
Notifications
You must be signed in to change notification settings - Fork 712
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 heavy to render a 900kB pdf #1950
Comments
Possibly related? #1923 |
Definitely seems related, thank you. Seems like there is active work going on that problem. Maybe we can look into the problem remaining? How can I reclaim the memory after printing the document?
I'm not familiar with memory stuff in Python. Tried to print the sizes of all the global variables but did not get much useful data |
#1496 may help you. |
At first I believed that #1923 was related (and it still might be) but I created a script that uses no CSS and the memory usage is still very high.
It creates an HTML document with a table with 5000 rows. The memory grows to about 1.5 GB, but then stays stable to subsequent generations. A user in #1496 stated that stuff gets cached and that is why is remains so big, but the speed for subsequent generations is not increased, it takes the same time of each. 1.5 GB is a lot to just keep allocated. Is there some way for me to reclaim it after generation as the same process might generate a few documents, but some time passes between each and I would rather allocate the memory when needed. |
I don't know much about memory handling either, but I looked at the memory size while stopping the process with the debugger. for i in range(10):
start = time.perf_counter()
html = weasyprint.HTML(string=the_html)
content = html.write_pdf(f'./test_{i}.pdf')
html = None
content = None
end = time.perf_counter()
printmem()
print(f"It took {(end - start):.2f} s for round {i}")
time.sleep(1) I tried overwriting it with None as shown below, but the memory usage did not change when changed to None. Although it says that it does not use css, it seems that it is affected by the css memory size because it uses default values to calculate the drawing position. I think it's probably the same story as #1496. I think you need to check Python implementation. |
@ssjkamei Thank you for taking a look. I think I'm going to have to spend a few hours trying to understand how weasyprint works under the hood to try and figure out what is going on here. Not sure what you mean by "check your Python implementation." Do you mean this is what it is and I need to make another plan to restart the process or something to clear out the memory? It's not meant in a bad way, just trying to make sure I understand your statement. Thanks |
Hi!
That’s something users want to do, but the short answer is: you can’t. Python doesn’t provide an interface to manage memory, even when using Python’s C interface, and that’s intended. Quoting the documentation:
Manually collecting the garbage collector can help, but that’s not deterministic: launch the same process multiple times, you may not get the same result. You can even delete So, if you really want to free the memory, the easiest way is probably to use dedicated processes. Here’s a StackOverflow thread about this topic. |
@Chris2L "check your Python implementation." |
No problem. Your English might not be good ;-) but your python rocks! Loving the updates you are pushing for your pull request. |
I'm using python 3.10.6 with weasyprint 59.0 on a linux VPS. I'm trying to generate a report that is about 220 pages long that is mainly tables (2 very long tables). First column is a name and job title and the rest of the columns are fontawesome icons.
I use the following code to generate a simple test:
When generating the pdf it takes up about 2 GB of RAM. I also need to exit the python application to reclaim that RAM.
I have a test.html, just not sure how to upload it here.
The questions are:
The text was updated successfully, but these errors were encountered: