Repository navigation
perf(filter): fuse Adaptive filter scoring and avoid redundant row passes - #740
Open
gatewaytofredom wants to merge 1 commit into
Open
gatewaytofredom wants to merge 1 commit into
gatewaytofredom wants to merge 1 commit into
Conversation
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.
Summary
Relates to #611.
Filter::Adaptive(the default filter forFast,Balanced, andHighcompression) currently runsfilter_internal+sum_buffersequentially for all 4 candidates(
Up,Sub,Avg,Paeth), writing and re-readingoutput4 times and recomputing the winning filter a 5th time wheneverPaethdoes not win.This replaces
adaptive_filter(sum_buffer, ...)with a fusedadaptive_filter_sumimplementation (100% safe Rust under#![forbid(unsafe_code)], byte-for-byte identicalfilter selection and output):
aarch64: Scores all 4 filters in a single read-only 32-byte pass usingu16inner accumulators (auto-vectorizes cleanly into NEONABS+UADDLV), thenmaterializes only the winning filter into
output.x86_64and other targets: Uses a register-friendly 2-stage 32-byte stack-chunk pass (scoringUp/Sub/Avgwithout writingoutput, then computingPaethdirectly into
outputwith early abort oncesum_paeth > min_cost), avoiding SSE2 XMM register spills while eliminating redundant full-row writes/re-reads.Benchmarks (1920×1080 RGBA, 7.91 MB raw, identical 3,820,442 B output)
aarch64)Fast + Adaptiveaarch64)Balanced + Adaptivex86_64default SSE2)Fast + AdaptiveTesting
filter::test::adaptive_filter_sum_matches_referenceverifying exactRowFilterand output byte equality againstadaptive_filter(sum_buffer, ...)across allBytesPerPixel, lengths (bpp..513), zero-cost short-circuits,-128boundary patterns, and random rows.cargo testpasses (102 unit + 8 integration + 8 doc tests) on bothx86_64-unknown-linux-gnuandaarch64-apple-darwin.