Skip to content

Do not retain empty JPEG APP and COM segments in applist - #10596

Merged
radarhere merged 2 commits into
mainfrom
jpeg-empty-app-markers
Nov 23, 2026
Merged

radarhere merged 2 commits into
mainfrom
jpeg-empty-app-markers

Conversation

@aclark4life

Copy link
Copy Markdown
Member

JpegImageFile.applist stored a tuple for every APP and COM segment, including empty ones (FF Ex 00 02). Empty segments carry no data, but each one costs about 120 bytes of Python objects for 4 bytes of input. A 16 MB JPEG made of empty APP0 segments retained about 470 MB.

This PR:

  • skips empty APP and COM segments when building applist (app and info behaviour is unchanged)
  • reuses constant APPn name strings instead of formatting a new string for every segment

With this change, the same 16 MB file retains about 2 KB.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aclark4life aclark4life added the 🤖-assisted AI-assisted label Nov 23, 2026
@radarhere
radarhere force-pushed the jpeg-empty-app-markers branch from dc32d94 to 4c6434d Compare November 23, 2026 07:23
@radarhere

Copy link
Copy Markdown
Member

self.app[app] = s # compatibility

This was marked as only present for 'compatibility' in PIL. If it becomes any more of an issue, I'd suggest deprecating.

@radarhere
radarhere merged commit 499864a into main Nov 23, 2026
119 of 121 checks passed
@radarhere
radarhere deleted the jpeg-empty-app-markers branch November 23, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants