Skip to content

perf(incentive): skip no-op buyer commits - #1270

Merged
thiras merged 2 commits into
mainfrom
perf/1260-skip-noop-buyer-commits
Jul 17, 2026
Merged

thiras merged 2 commits into
mainfrom
perf/1260-skip-noop-buyer-commits

Conversation

@altanoruc

Copy link
Copy Markdown
Contributor

Summary

  • abort buyer-channel write transactions on no-row outcomes instead of committing empty work
  • remove the redundant table_exists() read transaction from all four no-row operations
  • document Redb's abort-on-drop rollback mechanism and cover durable real deletions across reopen

Root cause

forget and forget_if_channel committed unconditionally, so an absent row or channel mismatch still paid for a Durability::Immediate fsync. All four operations also ran a separate read transaction to avoid persisting the table implicitly created by WriteTransaction::open_table, even though an aborted write transaction rolls that creation back.

Impact

No-row calls now use one write transaction and return before commit, avoiding both the preflight read and the no-op fsync. Actual deletions, progress advances, and deposit additions retain immediate durability, while compare-and-delete remains atomic in one serialized transaction.

Regression evidence

Removing only the pre-checks while retaining the old unconditional commit made no_row_ops_do_not_create_the_table fail with forget created the table. The same focused regression passes after the mutation guards, and a new reopen test confirms both deletion paths are durably committed.

Validation

  • cargo test -p decdn-incentive --features redb --quiet
  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo clippy -p decdn-incentive --no-default-features -- -D warnings
  • cargo clippy -p decdn-incentive --no-default-features --features buyer-store-core -- -D warnings

Closes #1260

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@altanoruc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: eb02ae0f-9b5b-4e47-8634-a191bbf2b8f8

📥 Commits

Reviewing files that changed from the base of the PR and between 45c2ef8 and d80725d.

📒 Files selected for processing (1)
  • crates/incentive/src/buyer_channel_table.rs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.92% (2488/2798 lines)
▲ +0.00pp vs base (88.92% → 88.92%)
Run: 29601457996

@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.34% (was 81.25%, ▲ +0.09%) — 48155/59205 lines

File Coverage Lines Δ
crates/incentive/src/buyer_channel_table.rs 91.74% 644/702 ▲ +0.48%
History
Commit Total Δ vs base
e885ceb 81.21% ▲ +0.01%
d80725d (HEAD) 81.34% ▲ +0.09%

@altanoruc

Copy link
Copy Markdown
Contributor Author

Review

Overview

Replaces the table_exists() preflight read transaction with a single write transaction per operation across all four no-row paths (forget, forget_if_channel, advance_progress, add_deposit), relying on redb's abort-on-drop to roll back the implicit table creation and skip the Durability::Immediate fsync when nothing was mutated. Net effect: no-row calls go from two transactions (read + write, sometimes with a no-op fsync) to one aborted write transaction.

Correctness — looks solid ✅

  • All early returns (Ok(()) on no-row forget, Ok(false) on missing/mismatched forget_if_channel, UnknownProvider/ChannelMismatch elsewhere) drop table then write_txn, so the transaction aborts and the implicit open_table creation rolls back. This is documented redb behavior and the updated no_row_ops_do_not_create_the_table test pins it.
  • Folding the existence check into the single serialized write txn actually removes the old benign TOCTOU window the deleted comment described — the check-and-act is now atomic. Nice side effect.
  • forget_if_channel keeps the compare-and-delete atomic in one txn; drop(value_guard) before remove is correctly placed. Returning Ok(true) unconditionally after commit is right since the mismatch/missing paths returned earlier.
  • forget semantics change (row absent → abort instead of empty commit) is invisible to callers: no state, same Ok(()).

Behavioral notes (fine, but worth stating)

  • No-row calls on a never-written store now take redb's exclusive writer slot (begin_write blocks on a concurrent writer) where the old path only needed a read txn. In the steady state (table exists) this is strictly better — the old code paid read txn plus write txn — so the trade only bites in the rare pre-first-write window. Seems clearly worth it.
  • Abort happens via Drop, which swallows any abort error. An explicit write_txn.abort() on the early-return paths would surface those errors, but rollback is in-memory and drop-abort is idiomatic redb — fine as is, just noting the choice is implicit.

Tests ✅

  • forget_deletions_survive_reopen closes the gap this refactor could open (deletion path silently losing its commit) and asserts the unrelated row survives — good.
  • The retained mutation-guard comments (Mutating that return to ChannelMismatch otherwise passes the whole suite) were accurately updated for the collapsed branches.

Nits (non-blocking)

  • forget performs the remove before discovering there was nothing to remove, inside a txn that then aborts. Harmless (the b-tree mutation is discarded), just mildly counterintuitive next to the get-first style of the other three ops.
  • Trailing comma in forget_if_channel(compare_deleted.provider, compare_deleted.channel_id,) in the new test — rustfmt won't touch macro interiors, so it'll linger.

Verdict: LGTM. Tight, well-documented perf fix with the right regression coverage; the doc comment on begin_durable_write now accurately describes the commit-only-after-mutation contract.

🤖 Generated with Claude Code

@thiras
thiras merged commit cdcbe8f into main Jul 17, 2026
23 checks passed
@thiras
thiras deleted the perf/1260-skip-noop-buyer-commits branch July 17, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(incentive): drop the no-op fsync in buyer forget/forget_if_channel — and the table_exists pre-check it exists for

2 participants