← Back to Pull requests

perf(database-watt): cut an upload from 12 messages to 6 #3

Open
unknown opened this pull request with 444 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 25, 2026 15:22 UTC
Author

An upload cost the storage worker 12 messages to the Database application: one for the bucket read, two for the permission probe before the S3 upload (the probe, then ROLLBACK), and nine for the write (the lock, the bucket and object reads, SAVEPOINT, the caller's probe, ROLLBACK TO and RELEASE SAVEPOINT, the INSERT, COMMIT). It now costs 6, for the same 19 statements in the same order:

  • A probe of one statement runs as one batch that ends in ROLLBACK. testPermission takes a singleStatement option, and connections that can do it provide rollbackStatementExecutor(); the batch request gains rollback. If the callback runs a second statement after all, the probe runs again as a regular transaction.

  • Statements whose result nobody reads, savepoint commands and scope statements, are deferred by the Watt transaction and sent with the next query (the new database.lockedBatch message) or with COMMIT (database.commitTransaction takes statements). ROLLBACK drops them; an error one raises is reported by the query it travelled with. A database.cancel stops a locked batch the way it stops a locked query.

  • - On Database Watt this means the "Failed to rollback savepoint" and "Failed to restore parent transaction scope" warnings no longer fire: such a failure fails the next statement instead, which aborts the transaction rather than carrying on under the wrong scope. A 25P02 from SAVEPOINT is mapped by that statement's error handling.
    - If a request carrying deferred statements is cancelled in flight, whether they ran is unknown, so the transaction can then only be rolled back.
  • The advisory lock and the bucket and object reads of a write go in one batch (Database.lockObjectForWrite). A lock timeout is still reported as LockTimeout and a missing bucket as NoSuchBucket.

  • - On Database Watt the upload's WaitObjectLock, FindBucketById and FindObject query timings become one LockObjectForWrite, so dashboards or alerts keyed on those names will see uploads drop out of them.

    The direct pg path keeps running these steps one by one.

    | Part of an upload | Messages before | Messages after |
    |---|---:|---:|
    | Bucket read | 1 | 1 |
    | Permission probe | 2 | 1 |
    | Write: BEGIN, scope, lock, bucket and object reads | 3 | 1 |
    | Write: SAVEPOINT and the caller's probe | 2 | 1 |
    | Write: ROLLBACK TO, RELEASE SAVEPOINT and the INSERT | 3 | 1 |
    | Write: COMMIT | 1 | 1 |
    | Total | 12 | 6 |

    The integration tests check the probe's and the write's counts against the Database application's own message stats. Inside the Database application, the same upload takes 9 round trips to Postgres instead of 15.

    Measured in Docker on one machine, with 4 storage workers, the Database application and pipelining on. The load was 1 KB upserts as service_role, this branch against 05aae5a6, medians of six rounds in alternating order:

    | | Before | After |
    |---|---:|---:|
    | Database thread CPU per upload, 200 uploads/s | 1,592 µs | 1,222 µs |
    | Database thread CPU per upload, saturated | 1,146 µs | 964 µs |
    | Postgres CPU per upload, 200 uploads/s | 2,316 µs | 2,094 µs |
    | Median upload latency, 200 uploads/s | 19.7 ms | 17.8 ms |

    The Database thread's figures were lower in every round, and Postgres CPU in five rounds of six. Halving the messages takes about a fifth off the Database thread's cost of an upload; the rest goes on the 19 statements themselves, which this does not change. Saturated throughput moved with the machine's load, and each build had the faster run in three rounds of six, so it is not quoted.

    Diff: 444 lines (+333 / -111) across 5 files Reviewer: ShogunPanda Review duration: 7888m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 444 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.2% · Safe to merge
    24.2%