perf(despeckle): skip the metrics-only component-counting passes#38
Merged
Conversation
clean() counted 8-connected components before and after every page — two full connected-component labelings, 13.5% of the page's time per the committed baseline — yet the counts feed nothing but the HTML report's charts and the summary log line. The pdfbook pipeline never sets a report dir, so its hot path paid for numbers nobody read. ProcessResult's component counts become OptionalInt (a counted 4-int convenience constructor keeps every existing construction compiling unchanged; componentsRemoved() stays present-or-zero int, documented). ProcessOptions grows collectComponentStats (default true via the delegating 5-knob constructor) plus a withoutComponentStats() wither. DespeckleService turns counting off exactly when no reportDir is set — the report path is byte-identical, including its charts and totals. The black-pixel counts still run unconditionally: they feed the 3% over-removal guard. Summary logs switch to always-measured black-pixel terms when counting was skipped. Measured: clean() 161.8ms -> 139.5ms single-threaded (-13.8%, matching the baseline's countConnComp share); pipeline at -j8 despeckle stage 10.19s -> 9.57s (-6.1%, the saving partially absorbed by memory- bandwidth saturation), conv -4.4%. The benchmark gains a "clean() without component stats" row pinning the pipeline-path number. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Why
clean()counted 8-connected components before and after every page — two full connected-component labelings, 13.5% of the page per the committed baseline — yet the counts feed nothing but the HTML report's charts and a summary log line. The pdfbook pipeline never sets a report dir, so its hot path paid for numbers nobody read.What
ProcessResult: component counts becomeOptionalInt; a counted 4-int convenience constructor keeps every existing construction compiling unchanged;componentsRemoved()stays present-or-zeroint(documented); newwithoutComponentStats(...)factory,hasComponentStats(),blackPixelsRemoved().ProcessOptions: 6th knobcollectComponentStats(defaulttruevia the delegating 5-knob constructor — all existing callers unchanged) +withoutComponentStats()wither carried throughwithDpi.LeptonicaPageCleaner: both counting passes guarded; the black-pixel counts still run unconditionally (they feed the 3% over-removal guard).DespeckleService: counting is on exactly whenreportDir != null— the report path (HTML charts, totals, the"N component(s) removed"line) is byte-identical. Without a report, the summary logs in always-measured black-pixel terms;PdfBatchServicedrops the would-always-be-0 component clause without reports.Measured
The −4.4% conv alone sits just under the 5% gate; it's a true work reduction (not a tradeoff) and compounds with the DWA morphology PR that follows.
Verification
./gradlew checkgreen; zero edits to existing test files' assertions (the compat constructors carry them).🤖 Generated with Claude Code