Skip to content

Public hook or event for live-query graph runs (for performance attribution) #1827

Description

@the-company-company-staging

Problem

We attribute main-thread long tasks to the sync stage that caused them using performance.mark pairs around our own collection commits (co:sync:commit:start/end). The other half of the picture, the time a commit spends re-running dependent live queries, has no public seam: CollectionConfigBuilder.executeGraphRun / maybeRunGraph run synchronously inside the source collection's commit and are private, and CollectionConfigBuilder is not re-exported from @tanstack/db.

What exists publicly today does not cover it:

  • createLiveQueryObserver subscribes to changes and status, not to the run itself.
  • createEffect's per-graph-run callback fires per effect query, so instrumenting it does not cover useLiveQuery / createLiveQueryCollection sites (we have ~65).
  • Collection events are status:change, subscribers:change, index:added, index:removed.

Patching the dist to wrap executeGraphRun works but is a vendor carry we do not want to maintain for a metric.

Request

A public, opt-in event around a live query's graph run, for example on the live query collection:

collection.on('graph:run', ({ id, durationMs, changes }) => { /* mark / measure */ })

or a global hook (onLiveQueryRun(listener)) that fires with { id, startTime, endTime } per executeGraphRun. Either lets consumers emit performance.mark pairs with detail: { collection: id } and lets DevTools-style tooling attribute long tasks to specific queries without touching internals.

Context

@tanstack/db 0.7.2. Related to the offset-regression issue we filed against electric-sql/electric#4806 in the same instrumentation effort.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions