feat(generate_markdown): --optimize-only retro pass over committed PNGs - #248
Merged
Merged
Conversation
optimize_pngs() is forward-only by construction — it sees only the render in progress, so pages built before it shipped keep their unoptimized images forever. 405 of the 429 PNGs committed across the six markdown workspaces are still RGBA; a measured sample puts them at 88.4MB -> ~23MB through the existing algorithm. Add --optimize-only, which renders nothing and walks markdown/**/<page>_files/ through the same optimize_pngs(), so a retro pass and a future re-render produce identical bytes (rather than a one-off pngquant sweep that would diverge from what the tool emits). optimize_pngs() now returns (before, after) byte totals so the walk can report what it reclaimed. The flag is checked before the PYAUTO_TEST_MODE guard on purpose: it executes no script and runs no search, so a truncated-search build cannot corrupt it. No dpi knob — quantize already delivers ~74% and a dpi drop would degrade every future render's readability for a smaller marginal gain. Verified end-to-end on a scratch copy of real autolens pages: 3.1MB -> 0.9MB (28%), dimensions preserved, already-optimized P-mode images left alone, and a second pass byte-identical (idempotent). PyAutoHands#247 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Aug 20, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the tooling half of PyAutoHands#247.
What
optimize_pngs()shrinks the figures nbconvert extracts, but it is forward-only by construction — it only ever sees the render in progress. Pages committed before it shipped keep their original PNGs forever. Across the six markdown workspaces, 405 of 429 committed PNGs are still RGBA, 88.4 MB of the 91.2 MB total.--optimize-onlyrenders nothing and walksmarkdown/**/<page>_files/through the sameoptimize_pngs(), so a retro pass and a future re-render produce identical bytes.optimize_pngs()now returns(before, after)byte totals so the walk can report what it reclaimed.Deliberately not a one-off
pngquantsweep (which would diverge from what the tool emits) and deliberately no dpi knob — quantize already delivers ~74%, and dropping dpi would degrade every future render's readability for a smaller marginal gain.The flag is checked before the
PYAUTO_TEST_MODEguard on purpose: it executes no script and runs no search, so a truncated-search build cannot corrupt it.API Changes
None.
--optimize-onlyis a new opt-in CLI flag; default behaviour is byte-for-byte unchanged.optimize_pngs()changes its return value fromNoneto(bytes_before, bytes_after). It is an internal helper of this module with one in-tree caller (render_script, which ignores the return) — no downstream consumer.Verification
pytest tests/— 354 passed, including 5 newTestOptimizeExistingcases (walks every_filesdir; leaves everything outsidemarkdown/alone; idempotent; no-markdown/and empty-markdown/no-ops).P-mode images correctly left alone, second pass byte-identical.Notes
This shrinks the working tree and future clone-of-tip, not
.githistory — the original blobs stay in the pack. No history rewrite is proposed.Heart at PR-open time:
stale(85), sole reasonrelease validation stale: source moved since rehearsal (PyAutoGalaxy)— unrelated to this repo.🤖 Generated with Claude Code