optimize snooze metadata updates and add benches#1159
Merged
Conversation
66b7abe to
07d56e4
Compare
brandur
approved these changes
Feb 25, 2026
Snoozed jobs with large `river:log` payloads were still paying an extra full-blob rewrite in `jobexecutor.reportResult`. The code marshaled `MetadataUpdates` and then used `sjson.SetBytes` to increment `snoozes`, which re-encoded the entire JSON payload. Change snooze handling to set `snoozes` directly in the `res.MetadataUpdates` map before marshaling. This keeps behavior the same while avoiding the second large copy. The method now funnels marshal logic through a small helper used by both snooze and non-snooze paths. Add focused benchmarks for this hot path, including 256 KB, 2 MB, and 8 MB `river:log` cases with both old-style and optimized approaches. Extend driver benchmarks with large metadata cases for `JobSetStateIfRunningMany` and `JobGetAvailable` to track driver-side amplification in fetch and update paths.
07d56e4 to
9f82746
Compare
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.
Following up on #1157, this is another metadata update optimization aimed specifically at job snoozing when the metadata payload is large.
Snoozed jobs with large
river:logpayloads were still paying an extra full-blob rewrite injobexecutor.reportResult. The code marshaledMetadataUpdatesand then usedsjson.SetBytesto incrementsnoozes, which re-encoded the entire JSON payload.Change snooze handling to set
snoozesdirectly in theres.MetadataUpdatesmap before marshaling. This keeps behavior the same while avoiding the second large copy. The method now funnels marshal logic through a small helper used by both snooze and non-snooze paths.Add focused benchmarks for this hot path, including 256 KB, 2 MB, and 8 MB
river:logcases with both old-style and optimized approaches. Extend driver benchmarks with large metadata cases forJobSetStateIfRunningManyandJobGetAvailableto track driver-side amplification in fetch and update paths.Benchmark results
go test ./internal/jobexecutor -run '^$' -bench BenchmarkMetadataUpdatesBytesForSnooze -benchmem -count=1Comparison uses:
marshal_plus_set_snoozes(old behavior)set_snoozes_in_map_then_marshal(new behavior)log_256kblog_2mblog_8mbNet: this change gives a modest CPU win and a large memory win on snooze metadata updates, especially at larger payload sizes.