Skip to content

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Mar 31, 2025

Follow-up to #131919, I noticed there was opportunity for improvement here too, a ~30% speed-up.

Benchmark textwrap new
indent 3.59 ms 2.81 ms: 1.28x faster

Benchmarked by indenting the contents of Objects/unicodeobject.c.

A

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is funny because this was my very first attempt at CPython: https://github.com/python/cpython/pull/107426/files :') It was rejected at that time (#107426 (comment)) though

@AA-Turner
Copy link
Member Author

Oh, I didn't see that PR! I think the optimisation is worth it, it's a small change and a reasonable speed-up for the default case (predicate=None). I'll give you co-authored-by credit!

A

@AA-Turner AA-Turner merged commit 51e0f2b into python:main Mar 31, 2025
45 checks passed
@AA-Turner AA-Turner deleted the tw-indent branch March 31, 2025 17:31
@@ -0,0 +1,2 @@
Improved performance of :func:`textwrap.dedent` by an average of ~1.3x.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/dedent/indent/

seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants