-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-128641: Fix ConfigParser.read Perfomance Regression #129596
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
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
1c339ab
to
7100857
Compare
Misc/NEWS.d/next/Library/2025-02-02-23-47-35.gh-issue-128641.GFs673.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. The changes look sound and certainly help elucidate the reported performance degradation.
This biggest problem with this change is that it doesn't capture the performance-sensitive concerns, so a future contributor (including myself having forgotten about these details) might refactor the code back to what it was (for example to reduce the number of logical branches or attribute accesses).
When I've encountered performance-sensitive parts of the code, I've done my best to (a) encapsulate the performance-sensitive aspects so they're identifiable and (b) include comments or docstrings to articulate their purpose. For example, in zipfile.Path, I added FastLookup:
cpython/Lib/zipfile/_path/__init__.py
Lines 177 to 193 in c537301
class FastLookup(CompleteDirs): | |
""" | |
ZipFile subclass to ensure implicit | |
dirs exist and are resolved rapidly. | |
""" | |
def namelist(self): | |
with contextlib.suppress(AttributeError): | |
return self.__names | |
self.__names = super().namelist() | |
return self.__names | |
def _name_set(self): | |
with contextlib.suppress(AttributeError): | |
return self.__lookup | |
self.__lookup = super()._name_set() | |
return self.__lookup |
This class encapsulated the performance optimizations, but also allows the concerns from the non-optimized version to be exposed separately (CompleteDirs). By disentangling these two concerns, it becomes more obvious why they're there and implemented that way. I'm not necessarily suggesting this pattern is appropriate here, though it could be.
The other thing I've done in these projects where possible is to include a regression test or benchmark that captures the performance expectations (example). Unfortunately, often these sorts of tests require sophistication that isn't available in the stdlib. Sometimes, however, it's possible to put in a test that will capture serious performance issues, such as hanging on an O(n^2) operation.
I've left some comments to specific lines of the code indicating areas where I'm uneasy with the change (or might have liked to have done things differently). Because of this uneasiness, I'd like to explore other options. I'm not expecting you to simply address the comments.
I'm happy to help explore other options, but currently, it seems we don't have a good reproducer, so I'll ask for that in the ticket.
@jaraco View my comments on review. The creation of an inline_comment from 3 blocks is combined into 1. Comprehension is broken down using lambda. News entry now reflects a return to previous performance rather than being misleading. |
Rely on re.sub to perform the substitutions in a unified way across full and inline prefixes.
…he variable name.
Use 'slots' to avoid '__dict__'.
40b4f1c
to
218db85
Compare
Co-authored-by: Bénédikt Tran <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these adjustments, I'm much happier with the approach and it regains the majority of the performance regression with a smaller diff and still mostly functional (paradigm) logic.
190 files Main: 94 - 100 ms You indeed applied the main optimizations and made the structure more logical. Now _LineParser does not pretend to be a line. Also, you combined full and inline strip. It might be better to rename the
|
As I read those options, I'm struggling to choose a best one. Pick the one you like best and let's go with that and get this merged. |
Ready to merge. |
…129596) --------- Co-authored-by: Jason R. Coombs <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.