Skip to content

gh-155152: Fix quadratic processing of concatenated zstd frames in zipimport - #155154

Merged
emmatyping merged 3 commits into
python:mainfrom
lpyu001:zstdimport
Oct 24, 2026
Merged

emmatyping merged 3 commits into
python:mainfrom
lpyu001:zstdimport

Conversation

@lpyu001

@lpyu001 lpyu001 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

The implementation uses _zstd.get_frame_size() to determine the compressed size of each Zstandard frame and passes only that frame to the decompressor. A memoryview enables zero-copy slicing while advancing through the input. This ensures each compressed byte is processed once, reducing cumulative input handling from O(N²) to O(N).

@lpyu001 lpyu001 changed the title gh-155152: Fix quadratic processing of concatenated zstd frames in zi… gh-155152: Fix quadratic processing of concatenated zstd frames in zipimport Aug 4, 2026
@lpyu001 lpyu001 closed this Sep 23, 2026
@lpyu001
lpyu001 deleted the zstdimport branch September 23, 2026 02:54
@lpyu001
lpyu001 restored the zstdimport branch September 23, 2026 03:01
@lpyu001 lpyu001 reopened this Sep 23, 2026
@brettcannon
brettcannon requested review from emmatyping and removed request for brettcannon October 15, 2026 20:44

@emmatyping emmatyping left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this looks good!

@emmatyping emmatyping added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 23, 2026
Comment thread Misc/NEWS.d/next/Library/2026-08-04-16-38-59.gh-issue-155152.qN1EEN.rst Outdated
…N1EEN.rst

Co-authored-by: Emma Smith <emma@emmatyping.dev>
@emmatyping
emmatyping merged commit 95e088e into python:main Oct 24, 2026
53 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @lpyu001 for the PR, and @emmatyping for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @lpyu001 and @emmatyping, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 95e088ed4964b438bc404c378f9f7915878ee5f7 3.14

@bedevere-app

bedevere-app Bot commented Oct 24, 2026

Copy link
Copy Markdown

GH-160565 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 24, 2026
@lpyu001

lpyu001 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Python 3.14's zipimport does not support Zstandard, so a backport should not be necessary

@emmatyping emmatyping removed the needs backport to 3.14 bugs and security fixes label Oct 24, 2026
emmatyping added a commit that referenced this pull request Oct 24, 2026
…zipimport (GH-155154) (#160565)

gh-155152: Improve performance of concatenated zstd frames in zipimport (GH-155154)
(cherry picked from commit 95e088e)

Co-authored-by: Pengyu Lee <lipengyu@kylinos.cn>
Co-authored-by: Emma Smith <emma@emmatyping.dev>
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.

2 participants