Skip to content

perf(sports): memoize guide hits and pre-pad tokens for sports matching - #388

Open
Kimlimp wants to merge 1 commit into
bilipp:mainfrom
Kimlimp:perf/sports-match-reuse
Open

Kimlimp wants to merge 1 commit into
bilipp:mainfrom
Kimlimp:perf/sports-match-reuse

Conversation

@Kimlimp

@Kimlimp Kimlimp commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

  • Pre-padded normalized tokens: Pre-pads normalized home and away team tokens (" \(token) ") once per fixture in FixtureMatchContext, and tournament tokens in competition matching. Eliminates repeated string allocations during candidate scoring via direct paddedTokens.contains { haystack.contains($0) }.
  • Per-resolve guide hit & miss memoization: Introduces MemoizedGuideHits to memoize bestEPGHit and competitionHit per EPG channel ID across clones during fixture resolution, skipping redundant guide scans for both hits and misses. In racing, memoizes bestRaceHit and airingAtStart per EPG channel ID across quality clones.
  • Candidate index intersection: Narrows the team-path candidate set using homeChannels.intersection(awayChannels) while preserving the full union with pickedChannels, competitionPhrases, and race candidates.
  • Multi-generation cache isolation: Updates ResolveCacheState to key cache entries by CacheGeneration dictionary instead of a single generation scalar, ensuring isolation across concurrent tests and background tasks without invalidating the generation lifecycle.

Performance Measurements

Verified on SportsQueryBenchmarks & SportsResolveScaleBenchmarks:

  • Peak memory reduction on SportsQueryBenchmarks from ~42,050 kB to ~41,080 kB (~1 MB reduction in peak allocation).
  • Scale benchmark (200 fixtures over 57k channels): Succeeded with zero retained physical memory growth and instantaneous warm cache reuse (0.005s).

Testing

  • Passed all 15 tests in SportsChannelResolverTests including new suites for:
    • Quality clones with no matching EPG programme (no-hit memoization).
    • Candidate index filtering single-team channels while retaining dual-team channels.
    • User picks without team tokens.
    • Split fields (epgSingleField).
    • Exhaustive reference comparison verifying identical scores, confidence, candidate ordering, and source attribution against unpruned matching.
  • Passed SportsChannelResolverIndexTests, SportsChannelResolverRacingTests, SportsChannelResolverTennisTests, and SportsResolveCacheTests.
  • Passed UI tests in SportsHubUITests (testSportsTabRenders, testNoBlockingCoverAppears, testManageTeamsSheetOpensAndDismisses).

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.

1 participant