rediff: speed up Optimize on real-world patches - #22
Open
leafo wants to merge 1 commit into
Open
Conversation
Three independent changes that together cut rediff wall-time materially on production patches while keeping the output size within 1% of the existing baseline: * bsdiff: vectorize writeMessages subtract loop. The per-byte bytes.Buffer.WriteByte loop that built each Add payload is replaced with a reusable []byte (DiffContext.addBuf) populated by a new 8-wide unrolled subtractInto helper. amd64 backend can keep the pipeline full and drop per-iteration bounds checks. Output is byte-identical to the previous implementation. * rediff: cache the decompressed patch body across analyzePatch and Optimize. analyzePatch already runs the full brotli decode pass over the patch body; previously Optimize re-decompressed the same bytes from scratch. The decompressed body is now held in a buffer on the rediff context and re-read via seeksource.FromBytes; the second decode pass is gone. Memory cost: ~1.5–2× the compressed patch size held between analyze and Optimize, released at the end of Optimize. * rediff: drop default brotli quality from 9 to 7 in defaultRediffCompressionSettings. On bsdiff'd Control streams q=7 is ~1.8× faster to encode than q=9 with <1% size growth. q=6 was also measured and produced +1.75% size on a real 275MB patch, exceeding the size budget — q=7 is the sweet spot. The field stays configurable via Params.Compression for callers that want to override. Measured against unmodified master on two real itch.io builds: 34MB-patch (multifile): 861ms → 459ms (1.876×, +0.046% size) 275MB-patch (multifile): 200.5s → 174.2s (1.151×, +0.655% size) All existing tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Three independent, low-risk changes that together cut
rediffwall-time materially on production patches while keeping output size within 1% of the existing baseline:writeMessagessubtract loop. The per-bytebytes.Buffer.WriteByteloop that built eachAddpayload is replaced with a reusable[]byte(DiffContext.addBuf) populated by a new 8-wide unrolledsubtractIntohelper. Output is byte-identical to the previous implementation.analyzePatchandOptimize.analyzePatchalready runs a full brotli decode over the patch body;Optimizepreviously re-decompressed the same bytes from scratch. The decompressed body is now held on the rediff context and re-read viaseeksource.FromBytes, eliminating the second decode pass. Costs ~1.5–2× the compressed patch size in memory between analyze and Optimize; released at the end ofOptimize.defaultRediffCompressionSettings. On already-bsdiff'd Control streams q=7 encodes ~1.8× faster than q=9 with <1% size growth. q=6 was measured too and produced +1.75% on a real 275MB patch, exceeding the size budget. The field stays configurable viaParams.Compression.Measurements
Against unmodified
master, on two real itch.io builds:Test plan
go test ./...passes (full suite)go test ./bsdiff/... ./pwr/rediff/...passesWriteBytepath🤖 Generated with Claude Code