Skip to content

gh-71648: Optimize PNG files - #138842

Merged
gpshead merged 4 commits into
python:mainfrom
StanFromIreland:optimize-images
Sep 12, 2025
Merged

gpshead merged 4 commits into
python:mainfrom
StanFromIreland:optimize-images

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Sep 12, 2025 •

Copy link
Copy Markdown
Member

OptiPNG version 7.9.1
Used command is: find . -name '*.png' | xargs optipng -o7

Combined png size on main:

2648366 bytes

Combined png size on pr:

2382587 bytes

That's a ~10% saving (without loss of quality).

Prior art: #8032

# Conflicts:
#	Doc/faq/python-video-icon.png

@zware zware 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.

I would suggest not messing with the images that don't shrink by multiple KB. Shaving off several bytes, even if it's a significant percentage of the total size, will wind up increasing the size of the overall repository anyway by adding a new blob, without meaningfully shrinking the size of any particular checkout.

@zware

zware commented Sep 12, 2025

Copy link
Copy Markdown
Member

It might be worth adding a pre-commit check (or workflow?) to check that images are not larger than they need to be when added or changed.

@StanFromIreland

Copy link
Copy Markdown
Member Author

This PR now only optimizes images where the savings are over 1 kb.

@gpshead gpshead added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Sep 12, 2025
@gpshead
gpshead enabled auto-merge (squash) September 12, 2025 20:05
@gpshead
gpshead merged commit 2e8f64c into python:main Sep 12, 2025
@miss-islington-app

Copy link
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

Sorry, @StanFromIreland and @gpshead, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 2e8f64c9317a327a2be1ab8031844ef3967c1040 3.14
@miss-islington-app

Copy link
Copy Markdown

Sorry, @StanFromIreland and @gpshead, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 2e8f64c9317a327a2be1ab8031844ef3967c1040 3.13
@StanFromIreland
StanFromIreland deleted the optimize-images branch September 12, 2025 20:28
StanFromIreland added a commit to StanFromIreland/cpython that referenced this pull request Sep 12, 2025
* Only keep > 1 kb savings
(cherry picked from commit 2e8f64c)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented Sep 12, 2025

Copy link
Copy Markdown

GH-138851 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 12, 2025
StanFromIreland added a commit to StanFromIreland/cpython that referenced this pull request Sep 12, 2025
* Only keep > 1 kb savings
(cherry picked from commit 2e8f64c)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented Sep 12, 2025

Copy link
Copy Markdown

GH-138852 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Sep 12, 2025
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Stable Refleaks 3.x (tier-3) has failed when building commit 2e8f64c.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1641/builds/909) and take a look at the build logs.
  4. Check if the failure is related to this commit (2e8f64c) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1641/builds/909

Failed tests:

  • test_os

Failed subtests:

  • test_remote_shutdown_receives_trailing_data_on_slow_socket - test.test_asyncio.test_ssl.TestSSL.test_remote_shutdown_receives_trailing_data_on_slow_socket
  • test_timerfd_ns_poll - test.test_os.TimerfdTests.test_timerfd_ns_poll

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_os.py", line 4536, in test_timerfd_ns_poll
    self.check_timerfd_poll(True)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_os.py", line 4521, in check_timerfd_poll
    self.assertEqual(self.read_count_signaled(fd), 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 2 != 1


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1592, in test_remote_shutdown_receives_trailing_data_on_slow_socket
    self.loop.run_until_complete(client(srv.addr))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/asyncio/base_events.py", line 719, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1576, in client
    await future
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1584, in wrapper
    meth(sock)
    ~~~~^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1502, in server
    self.assertEqual(data_len, CHUNK * SIZE*2)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 8388608
gpshead pushed a commit that referenced this pull request Sep 14, 2025
* Only keep > 1 kb savings
(cherry picked from commit 2e8f64c)
encukou pushed a commit that referenced this pull request Oct 7, 2025
* Only keep > 1 kb savings
(cherry picked from commit 2e8f64c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants