perf(search): rebuild PostgreSQL lookup path and stabilize live UI - #66
Merged
Merged
Conversation
blurbery
force-pushed
the
fix/postgres-search-performance-ui-stability
branch
from
August 29, 2026 04:29
bb03c20 to
b0e4af5
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.
Summary
Root causes found
lanternsplan visited roughly four million alias index entries.Gane of Thronshit the new 3-second safety cutoff; its plan assigned >112k cost to repeated alias-index filters.Gane of ThronsrankedJustice League: Throne of AtlantisaboveGame of Thrones.PostgreSQL lookup design
Normal FTS / prefix lookup
NOT EXISTS; PostgreSQL shows the overview scans asnever executedwhen title hits exist.episode_catalog_entriestable. Existing synchronous refresh triggers feed the search-field trigger, so no queue/watcher is required.DISTINCT.Typo recovery / relevance
Game of Thrones/Breaking Badplans during development.pg_trgmGIN scans. They areUNION ALLed, aggregated bycontent_id, permission-filtered, and hydrated once. No correlated alias rescan remains.Web stability and failure behavior
retry: falseand 30-second inactivegcTime; normal catalogue/request screens retain their existing policies.search_timeoutresponse and the UI hides stale results behind an explicit retry state.backdrop-filter/-webkit-backdrop-filter.Production-sized benchmarks
Catalogue: 15,826 media items, 141,104 aliases, 385,267 episodes, and 247,842 episode-catalog rows. Baseline
pg_stat_statementsfor the main old query was 4,659.2 ms mean and 26,187.7 ms max across 41 calls.Apples-to-apples old vs new plans
Measured with
EXPLAIN (ANALYZE, BUFFERS, TIMING OFF), limit 61, and a hard statement timeout. Final schema/index behavior was exercised with a transaction-local TEMP copy of the production-sized episode catalogue; that transaction was rolled back. Timeout gains are conservative lower bounds.llalanthelantstarlovedunethe mharry planternsBuffer evidence:
lanternsfell from 156,795 shared-buffer hits to 137 shared/local pages, and broadstarfell from 36,814 shared hits to 3,346 shared/local pages. The title-first plan marks both overview scansnever executedfor title-bearing searches.User example searches
The before figures below are old live HTTP resolver timings captured from the authenticated browser exercise/server logs. The after figures are the final PostgreSQL database-plan lookup, so they deliberately are not presented as direct end-to-end speedup ratios.
Game of ThronesBreaking BadFastThe exact-title guard skips fuzzy recovery for the first two.
Fastreturns the title family through normal indexed FTS/prefix search.Typo query and relevance checks
Read-only real-catalogue query, same 3-second statement timeout and pinned
pg_trgmthreshold:Gane of ThronsGame of ThronesBreking BadBreaking BadFast and FuriosFast & Furious, then related franchise titlesHary PoterAvengrs EndgmeAvengers: EndgameThe original word-only rank placed
Justice League: Throne of Atlantisahead ofGame of Thrones; the blended SQL and token/edit rerank correct that ordering.Bounded Go reranker
BenchmarkRerankFuzzyItemsCappedCandidateSet, 50 candidates × four aliases (the enforced worst case), Apple M4, five runs:This workload is constant with respect to total library size. There is no cache, goroutine, worker, or persistent in-process index to leak.
Browser and server checks
Game of Thrones→ clear →Breaking Bad→ clear →Fast, plus rapid 40 ms/key bursts and intermediate geometry sampling.opacity: 1,backdrop-filter: none). This PR makes that behavior explicit instead of inheriting translucent panel chrome.pg_stat_activityreported zero active FTS/trigram searches and a maximum active age of zero.Tests and guards
Game of Thrones,Harry Potter, alias-backed localized titles, auto edit limits, bounded distance, and cancellation.httptestlistener blocked by the desktop sandbox; repository CI remains the authoritative full Go/Web matrix.Migration and rollout notes
CREATE INDEX CONCURRENTLY..envchange, container restart, Compose down/up, deployment, or persistent production database change was performed while developing or benchmarking this PR.