Repository navigation
perf: reduce usage overview aggregation passes (#81, #158) - #165
Merged
Merged
Conversation
GavinKung
force-pushed
the
perf/issues-81-158-usage-overview
branch
from
October 22, 2026 15:00
fefa920 to
9c92230
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A populated usage overview currently runs 23 SQL statements even when the live window is empty. Repeated percentile scans and duplicate model aggregation make the dashboard slow as usage history grows.
Reduce a populated PostgreSQL overview to 12 statements. Compute exact nearest-rank percentiles with
percentile_discduring the totals, trend, and ordinary ranking aggregations; share the grouped model results between request-count and token-count rankings. Keep the existing credential pre-aggregation so auth resolution operates per credential index. The live summary now reads only the usage counters and latencies it returns.The API response and accounting rules remain unchanged. SQLite retains its existing percentile implementation and benefits from the smaller live query. There are no schema migrations, new query goroutines, database setting changes, timeout increases, or CPA/HMC contract changes. Large ranges still require work proportional to their matching records; these measurements are not a production latency guarantee.
Validation:
go build -o test-output ./cmd/home && rm test-output.Fixes #81.
Fixes #158.