-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
Move bits to native code? #670
Comments
Only recently started learning how Python packages are deployed, I'm wondering what you mean by 'native code'? Library files, aka .pyd/.dll/.so? Would than mean that everybody who wants to contribute to WeasyPrint had to setup the appropriate SDK (s)? Wondering also which parts of WeasyPrint could be made native and whether the nativeness would actually improve performance -- as you pointed out lot of time is spent with layout things (slowly tapering crenelated tower, wonderful metaphor ❤️ ). IMHO optimization of the layout code should be the first option before trying to rewrite (parts of) it in another language... |
Yes.
Depends whether the Python code remains as fallback or not.
I agree but according to the PRs/issues there have already been a number of these (e.g. #384, #638), and while I admittedly have almost no knowledge of the codebase aside from |
Native code ist faster. But... I confess: I dont like the idea very much, only as a last resort after cleaning up and optimizing the Python code. Of course it's a decision @liZe has to make, though I suppose he isn't keen on distributing platform-specific wheels instead of a single If there was a couple of contibutors, being able and willing to write and maintain native code, this was maybe an option ... if the queen had balls, she'd be king. |
It's a complex question.
Using a fast language may look as a good idea, but downsides are really important:
There's a lot of work that can be done to improve WeasyPrint's speed. Using a faster language is an option, but I think that there's a lot to do before. A golden rule I've learned about optimization is: "Don't try to make a function execute faster, try not to call it". WeasyPrint is the perfect project to follow this rule, because its code is often naive and does too many things that could be avoided. You're right, |
Fair enough. |
Colleagues have been looking at weasyprint as a possible replacement for wkhtml as it's definitely more approachable & debuggable (than a huge complex pile of C++ especially for people with limited knowledge of C++ but good knowledge of Python), seems well-built and can be both used as a library and shelled out. And is less likely to segfault and regress than wk.
The sticking point so far is performances, as known from various issues on the tracker. Now from a test report the only bit which stands out would be
get_all_computed_style
which is40% according to cprofile or 2025% according to flamegraph (the report is not the most complex but is pretty large and has a lot of non-specific CSS to deal with) with the rest being spent in a large and slowly tapering crenelated tower of layout things (an other hotspot of sorts is iter_lines but that's likely in large part because it's called a lot and ultimately does quite a bit of work).And so I've been wondering if maybe subsystems should be moved to native code entirely, and if that sounds fine which tech you'd prefer (e.g. cython, python extension, move more code on the other side of CFFI, and in the latter two cases whether the native bits should rather be in C or Rust or something else).
The text was updated successfully, but these errors were encountered: