Skip to content

feat: per-phase query latency breakdown in the frame header#415

Open
shaunpatterson wants to merge 5 commits into
dgraph-io:mainfrom
shaunpatterson:sp/latency-breakdown
Open

feat: per-phase query latency breakdown in the frame header#415
shaunpatterson wants to merge 5 commits into
dgraph-io:mainfrom
shaunpatterson:sp/latency-breakdown

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

What

Dgraph returns a per-phase latency breakdown with every response (extensions.server_latency: parsing / processing / encoding / …) but Ratel discarded it. This PR surfaces it as a color-coded multi-segment bar in the frame header with a per-phase tooltip (time + percentage per phase, plus network time and total).

Also fixes a latent bug

The existing frame-header latency bar was dead code: it read frame.serverLatencyNs, but the timing has always been stored on frameResults[frameId][tab] — so the bar never rendered at all. FrameHeader now receives the tab result and renders from it.

How

  • lib/latency.js — pure helpers turning server_latency into ordered, labelled segments: known phases in pipeline order (parsing → processing → encoding → assign timestamp), unknown *_ns fields the server may add later included with prettified labels (future-proof), total_ns excluded as redundant. 9 unit tests.
  • frames reducer keeps the raw server_latency object on the frame result (alongside the existing summed fields).
  • Segment colors per phase + network in FrameHeader.scss.

Testing

9 unit tests across formatting, segment ordering, zero-skipping, unknown-phase inclusion, ratio math and tooltip text. npm run build passes.

🤖 Generated with Claude Code

Dgraph returns a per-phase latency breakdown with every response
(extensions.server_latency: parsing/processing/encoding/...), but
Ratel discarded it - and the frame header latency bar was dead code:
it read frame.serverLatencyNs while the timing lives on
frameResults[id][tab], so it never rendered at all.

- lib/latency.js: pure helpers turning server_latency into ordered,
  labelled bar segments (known phases in pipeline order, unknown *_ns
  fields included future-proof, total_ns excluded) plus tooltip text.
  9 unit tests.
- frames reducer keeps the raw server_latency on the frame result.
- FrameHeader now receives tabResult and renders a multi-segment
  color-coded bar (parsing/processing/encoding/network) with a
  per-phase tooltip showing times and percentages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shaunpatterson shaunpatterson requested a review from a team as a code owner June 12, 2026 17:38
@rahst12

rahst12 commented Jun 16, 2026

Copy link
Copy Markdown

This is a nice touch, much nicer than reading the JSON.
image

Thoughts: The time displayed without hover is Processing + Encoding. I'd expect it to be total time.

What do you think about adding a click-able breakdown like this:
image

Claude helped me out with the little prototype: Please update the latency hover to be a click and pop-up in addition to the hover. I want to see each portion of the query phase as a bar on a sequence diagram with a total time.

@rahst12

rahst12 commented Jun 16, 2026

Copy link
Copy Markdown

Something like too.. to give you an idea of how many nodes returned.. which may contribute to the processing/encoding/network time.

image

Address review feedback on the latency bar:

- The collapsed headline now shows the grand total (server phases + network),
  not parsing+processing+encoding, matching what users expect from "total".
- Clicking the latency bar opens a 'Query latency breakdown' modal (the hover
  tooltip is kept) with one labelled, colored bar per phase plus a total row.
- A 'Num UIDs' section counts the values each predicate contributed to the
  response (scalars once, child lists by length), a proxy for how much data
  the query returned and thus its processing/encoding/network cost.

countPredicates/numUidSegments are pure and unit-tested.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shaunpatterson

Copy link
Copy Markdown
Contributor Author
image

@shaunpatterson

Copy link
Copy Markdown
Contributor Author

Waterfall
image

shaunpatterson and others added 3 commits June 15, 2026 21:52
Per review, the Latency section now reads as a sequence over the total
query duration: each phase bar starts where the previous phase ended
(offset by cumulative elapsed time) instead of every bar starting at
zero. Num UIDs bars stay left-aligned as plain counts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The modal chrome is themed centrally, but the latency/num-uids bar tracks
rendered bright white and labels were dim in dark mode. Add
[data-theme=dark] overrides (co-located with the component) so the empty
tracks use the dark elevated surface, the total rule/border use the dark
border, and labels/values stay legible.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The 120px label column truncated 'Assign timestamp' to 'Assign timesta...'.
Widen to 150px so the longest phase label fits without ellipsis.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants