OPT: Skip upgrade_record match when upgrade not needed#123
Open
wtn wants to merge 1 commit intodatabento:devfrom
Open
OPT: Skip upgrade_record match when upgrade not needed#123wtn wants to merge 1 commit intodatabento:devfrom
wtn wants to merge 1 commit intodatabento:devfrom
Conversation
threecgreen
requested changes
Apr 16, 2026
Contributor
threecgreen
left a comment
There was a problem hiding this comment.
This is a nice change. I'm also seeing 6-15% improvement in throughput for uncompressed (lowest with mbp-10) and 2-9% improvement for zstd-compressed.
You should update the CHANGELOG to mention this optimization, and please "credit: " yourself, as in previous PRs.
threecgreen
requested changes
Apr 17, 2026
Contributor
|
LGTM. I will commit this change and it'll be mirrored to GitHub |
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.
While profiling a local replay scenario, I saw
DbnFsm::upgrade_recordtaking a meaningful share of decode CPU on current-version data decoded withVersionUpgradePolicy::AsIs, a workload where the function has nothing to do. The per-record match over(version, policy, rtype)runs and falls through every arm.The proposed change caches whether the
(policy, version)combo can ever trigger an upgrade. When it can't,process()skips the dispatch and transitions straight toConsume.Implementation, benchmark, and reproducer script
Implementation
upgrade_record_with_versionis the match in question. Its arms only fire on old-version data under a non-AsIspolicy (v1→v2InstrumentDefMsg, v2→v3StatMsg, etc.); for current-version data orAsIs, every arm is skipped and the function returns the record unchanged. The work is wasted on the common path.Approach:
needs_upgrade: boolonDbnFsm.upgrade_policyorinput_dbn_version:new,Default, the builder'sbuild,set_input_dbn_version,set_upgrade_policy,decode_prelude(metadata path),reset.process()andprocess_multiple(), when!needs_upgrade, skip theupgrade_recordcall and the compat-buffer bookkeeping, transitioning toConsumewith aRecordRefbuilt directly from the main buffer.No public API change;
upgrade_recordstays in place for the slow path.Benchmark
MacOS
sample(1)on a 395 MiB MBO replay (5 s):upgrade_recordtook ~14% of decode-loop CPU on upstreammain. After PR #122 lands, that same absolute time is ~19% of the smaller total. Expected throughput gain onAsIsworkloads of 15-25%.Synthetic
decode_ref, peak throughput over N=2M records, 30 iters,arm64-darwin25:Reproducer
Copy the script below into
rust/dbn/examples/decode_bench.rs, then:Defaults:
N=1_000_000records × 5 schemas, 20 timed iters, 3 warmup. Override via env vars (N,ITERS,WARMUP).For a before/after comparison: run on
mainfor a baseline,git switchto this branch, re-run.Type of change
How has this change been tested?
test_compute_needs_upgrade: parameterized rstest (11 cases) covering each policy and version combination (including unknown version).test_needs_upgrade_refreshed_on_setters: walks each mutation site (set_input_dbn_version,set_upgrade_policy,reset) and asserts the cache stays consistent.test_dbn_identityrstest matrix covers both branches:(v3, AsIs)/(v3, UpgradeToV3)/(v2, UpgradeToV2)hit the fast path;(v1, UpgradeToV2)/(v1, UpgradeToV3)/(v2, UpgradeToV3)hit the slow path.cargo test -p dbn --features async --libpassesChecklist
scripts/build.sh)scripts/lint.shandscripts/format.sh)scripts/test.sh)Declaration
I confirm this contribution is made under an Apache 2.0 license and that I have the authority necessary to make this contribution on behalf of its copyright owner.