Skip to content
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

[3.13] gh-126565: Skip zipfile.Path.exists check in write mode (GH-126576) #126642

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 10, 2024

When zipfile.Path.open is called, the implementation will check
whether the path already exists in the ZIP file. However, this check is
only required when the ZIP file is in read mode. By swapping arguments
of the and operator, the short-circuiting will prevent the check from
being run in write mode.

This change will improve the performance of open(), because checking
whether a file exists is slow in write mode, especially when the archive
has many members.
(cherry picked from commit 160758a)

Co-authored-by: Jan Hicken janhicken@users.noreply.github.com

…onGH-126576)

When `zipfile.Path.open` is called, the implementation will check
whether the path already exists in the ZIP file. However, this check is
only required when the ZIP file is in read mode. By swapping arguments
of the `and` operator, the short-circuiting will prevent the check from
being run in write mode.

This change will improve the performance of `open()`, because checking
whether a file exists is slow in write mode, especially when the archive
has many members.
(cherry picked from commit 160758a)

Co-authored-by: Jan Hicken <janhicken@users.noreply.github.com>
@jaraco jaraco enabled auto-merge (squash) November 10, 2024 15:03
@jaraco jaraco merged commit 0d3aa25 into python:3.13 Nov 10, 2024
40 checks passed
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