35% better performance on scripts/benchmark_big_table.py
#68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @pelme, I know this is unsolicited, but I thought I'd put it out there for you to take a look.
I noticed in some benchmarking that the
isinstance(x, str | _HasHtml)line was taking up a lot of the runtime on the benchmark. I replaced it with ahasattrcall (to check for the__html__attribute), which turned out to be faster.There's definitely a tradeoff here, because now we've got this awkward hasattr in the if, elif, elif checks, whereas all the others are checking
isinstance. I also am not 100% sure here on all of the ramifications of checking for the__html__attribute.I'll leave it up to you if you think the optimization here is worth it. I don't have a great feel for the usage of this library to understand how important this codepath is, or how much this would help in real world usage...just thought I'd put it out there for your look.
Thanks for making a great abstraction for html in python!
Benchmarks
Prior to change
After Change
Original Results from Line Profiler: