-
-
Notifications
You must be signed in to change notification settings - Fork 686
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
Possible optimizations - do not merge #638
Conversation
Fix Kozea#586. For some reason I don't really understand, stripping trailing spaces that would make the line too long can't be optimized when the space is at the end of the block. Returning None instead of the index of the last letter should be possible, but it breaks the rendering when the first letter of the next line box starts with a character that doesn't allow line breaks after spaces (many punctuation characters for example) and that doesn't allow line wrap. This change shouldn't be harmful, as the removed code lines were just cleaning the resume_at value without changing the logic of line breaking. I suppose that there's a bug somewhere else.
To be safe the The condition for the short circuit isnt But wow! 25% speedup by not directly accessing attributes -- didnt know that attribute lookup is that slow in Python. Good to know. There must be many (other, better?) places, especially in the layout code, where local variables could be used to avoid the lookups... |
@chancyk Thanks a lot for your optimizations! I know how hunting speed improvements can sometimes be frustrating and I really appreciate when other people take the time to
That's perfectly right! 3210ea8 makes WeasyPrint faster but probably breaks many use cases.
It's logically true, but in this case
Actually, they're not that slow, it's WeasyPrint's fault, here's why (long story, you can skip): There used to be a class called Dicts in Python are used for everything and are optimized in each Python version (sometimes heavily, like in 3.6, see #70). A simple way to make WeasyPrint really faster was to replace the
That was not enough. Inheriting from I've cherry-picked 71f7415, mainly as it avoids calling If you find other optimizations on PS: @chancyk I'd be really interested in your performance results using the current |
I was profiling WeasyPrint and came across a few optimizations that were a 25% speed increase on my particular use case.
3210ea8 simply caches
Box.margin_height()
because it gets called thousands of times. This is the largest speedup though all three are respectable. Is this safe?89e269a see if
hypothetical_position
is already greater thanshape.position_y
before performing attribute lookups.71f7415 just assign locals instead of performing 9 different attribute lookups in the original list comprehension.
Thoughts?