Skip to content

perf(subgraph): cut per-event store round-trips #138

Description

@silent-cipher

Problem

Two guaranteed-miss Postgres lookups happen on hot paths:

  1. Transaction dedup via Transaction.load() in every handler (handleDataSetCreated, handleDataSetDeleted, handleStorageProviderChanged, handlePossessionProven, handleNextProvingPeriod, handlePiecesAdded in subgraph/src/pdp-verifier.ts). A transaction's events are always processed within one block, so the entity can only pre-exist in the in-block cache — but load() on a not-yet-existing entity is a guaranteed DB round-trip for the first event of each tx.

  2. Root.load() existence check in handlePiecesAdded (pdp-verifier.ts:1109-1116). The contract's nextPieceId is monotonic — piece IDs are never reused — and the code's own log message says "This shouldn't happen." That's one DB miss per piece added during backfill.

Proposal

  • Replace Transaction.load(id) with Transaction.loadInBlock(id) at all sites (apiVersion is 0.0.9, so it's available). This is the documented use case for loadInBlock: entities created earlier in the same block.
  • Drop the Root.load existence check and construct the Root unconditionally.

Acceptance criteria

  • No Transaction.load() remains in pdp-verifier.ts
  • No existence check before Root creation in handlePiecesAdded
  • Tests pass (multi-event-per-tx fixtures still produce a single Transaction entity)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    • Status
      🐱 Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions