Skip to content

perf: reduce artwork, subtitle and playback statistics work - #35

Merged
blurbery merged 4 commits into
mainfrom
perf/artwork-cancellation-playback-stats
Sep 26, 2026
Merged

blurbery merged 4 commits into
mainfrom
perf/artwork-cancellation-playback-stats

Conversation

@blurbery

@blurbery blurbery commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Problem and reproduction

Fast catalogue browsing could leave artwork work running after its last consumer disappeared. Playback telemetry repeatedly rebuilt statistics, and every playback tick scanned and republished external subtitle cues even when nothing changed.

This PR combines the artwork/statistics changes with the subtitle change in separate PR #36 for one GitHub release. Metadata-cache retention is outside this change.

Implementation and impact

  • Cancel shared image work only after its last consumer leaves. Preserve other consumers, different image sizes, replacement requests and account isolation; skip abandoned queued decodes.
  • Limit routine statistics projection to the existing 0.9-second interval while delivering buffer readings immediately. One pending refresh publishes the latest sample even if playback is paused and no further event arrives. Forced updates, new loads and cleanup cancel that pending work.
  • Advance external text subtitles through indexed cue boundaries. Preserve overlaps, file order, track identity, seeks and delays, and suppress unchanged or empty publications. Parsing, styling and native embedded/ASS rendering remain unchanged.
  • Add focused iOS/tvOS regression coverage using existing media fixtures. No provider API, playback engine or dependency changes.

Validation

  • Combined commit ef893c40a231c0e95d9f4b65f412b9e4ec5514fe: 43 targeted iOS tests and 40 tvOS tests passed on OS 27.0 simulators, both with complete result bundles and successful runner exits.
  • xcodebuild build-for-testing followed by xcodebuild test-without-building, with sequential platform execution and test parallelism disabled. Suites: ImageDataCoalescingTests, VividPlaybackStatsProjectionTests, VividSubtitleCueCursorTests, plus three existing iOS ASS/SRT/WebVTT loader tests.
  • The statistics suite verifies actual throttling, final-sample publication without another event, immediate buffer updates and cancellation across unavailable telemetry, load changes and cleanup.
  • The subtitle suite compares results with the original full filter across generated timelines, overlaps, boundaries and seeks, and tests dual subtitles, delays, track changes, loading failures and cancellation.
  • Both platforms exercise synthetic playback, pause and seek, with frame-tolerant landing-position checks and preserved pause intent.
  • Prior artwork/statistics validation: 59 iOS and 25 tvOS cases passed. python3 scripts/tests/playback-end-recovery-tests.py passed 178 end/recovery and 33 early-display checks; python3 scripts/tests/playback-auth-refresh-tests.py passed 29 checks.
  • git diff --check passed. The combined Player regression run passed for ef893c4: 1,077 iOS tests with 2 skipped and 0 failures, plus the tvOS simulator build, focused script checks and synthetic playback preview check. The earlier perf: avoid redundant external subtitle scans and updates #36 CI run failed one exact seek-time assertion because the decoder landed at 0.125 seconds for a 0.1-second request. The test now allows a 0.05-second frame tolerance while still checking seek completion, pause intent and load identity; both simulator reruns passed.

Performance

No application benchmark was run. The cadence test permits two projections from 1,000 synthetic timestamps across one second. Subtitle tests observe no empty publications with subtitles off, and one publication across 1,000 unchanged-caption clock updates.

Testing status

  • Tested: Targeted simulator regression tests on the combined source.
  • Environment: iOS/tvOS 27.0 simulators with Xcode 27.0.
  • Revision: Combined simulator source ef893c40a231c0e95d9f4b65f412b9e4ec5514fe.
  • Checks and results: Completed simulator results are listed above. Both original CodeRabbit findings were fixed, replied to and resolved. CodeRabbit completed its review of the combined ef893c4 revision, with no unresolved findings.
  • Limitations: The combined revision has simulator validation only. No exhaustive provider, real-world subtitle, AirPlay, hardware-decoding or network-recovery matrix, Release archive validation or measured performance comparison was performed. In-progress decoding cannot be interrupted mid-decode; backward subtitle seeks rebuild the active selection.

Design impact and approval

  • Design impact: No design changes.
  • Approval from blurbery: Not applicable, no design changes.

Documentation impact

Updated the existing browsing and playback architecture guides for image cancellation, statistics cadence and subtitle cue updates.

AI disclosure

Implemented these changes with Codex as a tool.

Preserve shared image consumers while cancelling abandoned requests and queued decodes. Limit routine statistics projection while keeping recovery and timeline buffers current. Add focused iOS and tvOS regression coverage.
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: blurbery/vivid/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 9d715bf5-d466-4538-8bb8-4d5ad50f7bc3

📥 Commits

Reviewing files that changed from the base of the PR and between 8f65713 and ef893c4.

📒 Files selected for processing (8)
  • docs/playback/architecture.md
  • iosApp/Tests/VividPlaybackStatsProjectionTests.swift
  • iosApp/Tests/VividSubtitleCueCursorTests.swift
  • iosApp/iosApp/Playback/MPV/VividMPVPlayer.swift
  • iosApp/iosApp/Playback/VividSubtitleCueCursor.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/VividPlaybackStatsProjection.swift
  • iosApp/project.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Image requests now track separate consumers and cancel shared transfers when the last consumer leaves. External subtitle cues use indexed boundaries and publish only when selections change. Playback statistics use delivered telemetry samples, update buffer measurements independently of formatting cadence, and include added tests and documentation.

Changes

Image pipeline cancellation

Layer / File(s) Summary
Shared image-flight and decode cancellation
iosApp/iosApp/Shared/VividImagePipeline.swift, iosApp/Tests/ImageDataCoalescingTests.swift, docs/apple-tv-browsing.md
Image flights track individual waiters and cancel a shared transfer when its last waiter leaves. Queued decodes check cancellation and do not cache cancelled results. Tests cover shared consumers, prefetches, replacement flights and account changes. Documentation describes the cancellation behaviour.

External subtitle cue selection

Layer / File(s) Summary
Cue cursor selection and validation
iosApp/iosApp/Playback/VividSubtitleCueCursor.swift, iosApp/Tests/VividSubtitleCueCursorTests.swift
The cue cursor indexes valid cue boundaries and updates selections as playback time changes. Tests compare selections with interval filtering and cover cue content and timing cases.
Subtitle publication through player updates
iosApp/iosApp/Playback/MPV/VividMPVPlayer.swift, iosApp/Tests/VividSubtitleCueCursorTests.swift, docs/playback/architecture.md
The player stores cue cursors and updates published cues when the track or selected offsets change. Tests cover track selection, delays, seeks, stopping and load outcomes.

Playback statistics telemetry

Layer / File(s) Summary
Telemetry samples and refresh cadence
iosApp/iosApp/Screens/Player/VividPlaybackController.swift, iosApp/iosApp/Screens/Player/VividPlaybackStatsProjection.swift, docs/playback/architecture.md
The controller forwards delivered telemetry samples, and statistics snapshots use the supplied sample. A monotonic cadence limits non-forced refreshes to once every 0.9 seconds.
View-model integration and tests
iosApp/iosApp/Screens/Player/PlayerViewModel.swift, iosApp/Tests/VividPlaybackStatsProjectionTests.swift, iosApp/project.yml
The view model updates buffer measurements before rate-limiting statistics formatting and resets cadence and read-ahead state during load resets and cleanup. Tests cover telemetry updates, cadence and playback operations. The project adds a tvOS test target.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant ImageRequest
  participant VividImageFlights
  participant SharedTask
  ImageRequest->>VividImageFlights: register or cancel waiter
  VividImageFlights->>SharedTask: start or join shared transfer
  VividImageFlights->>SharedTask: cancel when no waiters remain
Loading
sequenceDiagram
  participant TelemetryPublisher
  participant VividPlaybackController
  participant PlayerViewModel
  participant VividPlaybackStatsCadence
  TelemetryPublisher->>VividPlaybackController: deliver telemetry sample
  VividPlaybackController->>PlayerViewModel: emit telemetryChanged with sample
  PlayerViewModel->>VividPlaybackStatsCadence: check refresh cadence
  PlayerViewModel->>PlayerViewModel: update buffer measurements
Loading

Merge Risk: ⚪ Minimal · up to ef893

No actionable merge-blocking issue was established for the current change. It is ready to merge after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ef893

The changes remain within the app’s artwork and playback flows. The reviewed paths preserve account-scoped artwork requests and player-owned subtitle state, with no identified new security exposure. Some broader security and runtime coverage remains unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed artwork-flight behavior affects requests within the client pipeline; request and session scoping provide a boundary between account scopes. Subtitle cursor state remains owned by a player instance.

Trust Boundaries and Controls

  • observed — The changed subtitle updater is private, and its published cue arrays remain player-owned. Existing playback-time, selection, load, and stop paths drive updates; the reviewed change does not add an externally writable cue-publication entrypoint.

Resilience and Maintainability Implications

  • observed — Track identity participates in cue-publication equality, and late subtitle loads are generation-checked. Tests cover matching cue IDs across tracks, independent primary and secondary selections, backward seeks, and clearing.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.80% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 79 functions across 9 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarises the main changes: reducing artwork, subtitle, and playback statistics work. It is concise and specific.
Description check ✅ Passed The description directly explains the artwork cancellation, playback statistics throttling, and subtitle cue changes. It also provides relevant validation results and limitations.
Full details: Docstring Coverage

Explanation

Docstring coverage is 3.80% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 79 functions across 9 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@blurbery

Copy link
Copy Markdown
Owner Author

@coderabbitai review

Please review the artwork cancellation and playback-statistics changes, particularly shared-consumer cancellation races, account isolation, immediate buffer updates and regression coverage.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: blurbery/vivid/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7a8d8021-be80-439b-b827-12988161fbc3

📥 Commits

Reviewing files that changed from the base of the PR and between e13a1d7 and 8f65713.

📒 Files selected for processing (9)
  • docs/apple-tv-browsing.md
  • docs/playback/architecture.md
  • iosApp/Tests/ImageDataCoalescingTests.swift
  • iosApp/Tests/VividPlaybackStatsProjectionTests.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/VividPlaybackController.swift
  • iosApp/iosApp/Screens/Player/VividPlaybackStatsProjection.swift
  • iosApp/iosApp/Shared/VividImagePipeline.swift
  • iosApp/project.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread iosApp/iosApp/Screens/Player/VividPlaybackStatsProjection.swift
Comment thread iosApp/Tests/VividPlaybackStatsProjectionTests.swift
@blurbery blurbery changed the title perf: cancel unused artwork work and throttle playback statistics perf: reduce artwork, subtitle and playback statistics work Sep 26, 2026
@blurbery

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@blurbery

Copy link
Copy Markdown
Owner Author

@coderabbitai review

Please review the combined changes in ef893c4, including the subtitle cursor and publication checks from #36 and the fixes for both earlier findings. The combined iOS CI suite and tvOS build are green; targeted simulator tests passed on both platforms.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@blurbery
blurbery merged commit 15479aa into main Sep 26, 2026
3 checks passed
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