Skip to content

perf(observations): count identical tag lists before sorting scopes (#6328) - #6404

Merged
nicoloboschi merged 1 commit into
mainfrom
triage/6328
Nov 6, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
triage/6328

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Closes #6328. Based on @harshitgupta31415's patch.

GET /observations/scopes sorted every observation's tags twice — once for the total, once for the page. Most observations share the same few tag lists, so this now counts identical lists first, sorts only the distinct ones, and reads both the page and the total from one result.

Observations (53 tag sets) Before After
100k 287 ms 33 ms
1M 3.16 s 107 ms
100k, filtered to one tag 32 ms 15 ms

Output is identical (scopes, counts, order, total — including an empty page past the end).

Changes on top of the reporter's patch: dropped the old-query fallback for non-Postgres backends (Oracle cannot run unnest, so it never worked there), and added a comment explaining the query shape.

…6328)

GET /observations/scopes sorted every observation's tags twice (once for
the total, once for the page). Count identical tag lists first, sort only
the distinct ones, and read page + total from one materialized result.
287 ms -> 33 ms at 100k observations, 3.2 s -> 0.1 s at 1M.

Review fixes on top of the reporter's patch: dropped the kept old-query
branch for Oracle (Oracle cannot run unnest, so it was dead code) and
commented why the query is shaped this way.

Closes #6328

Co-authored-by: Harshit Gupta <[email protected]>
@nicoloboschi
nicoloboschi merged commit 717dd6d into main Nov 6, 2026
112 checks passed
@nicoloboschi
nicoloboschi deleted the triage/6328 branch November 6, 2026 13:58
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.

reuse tag counts when listing observation scopes (2.01 s → 190.46 ms, 10.57× faster)

1 participant