Skip to content

PGS subtitles cause high CPU usage #628

Closed

Description

@ijuniorfu

What happened?

Description

When playing a 70 GB Blu-ray MKV file, enabling PGS subtitles causes significantly higher CPU usage.

CPU Usage

PGS Subtitles CPU Usage
Disabled Peak: ~65%, Average: ~35%
Enabled 100%+

Environment

  • Source: Blu-ray MKV
  • File size: ~70 GB
  • Subtitle format: PGS
  • Measurement: Xcode Instruments – Time Profiler

Profiling

With PGS subtitles enabled, imageForSubtitleRect in EmbeddedSubtitleDecoder.swift is the top CPU-consuming function on the Main Thread.

Call stack:

imageForSubtitleRect
└── decodeStoredSubtitlePacket
    └── subtitleDrainTick
        └── startSubtitleDrainer

The CPU usage drops significantly when PGS subtitles are disabled.

Expected Behavior

PGS subtitle rendering should not cause excessive CPU usage during playback, especially when the subtitle content is not changing frequently.

Additional Information

The issue appears to be related to PGS subtitle bitmap processing in imageForSubtitleRect.

Steps to reproduce

none

AetherEngine version or commit SHA

4ef5ef9

Host app

Custom / my own integration

Platform

iOS

OS version

iOS26

Device / chip

iPhone16

Playback path

Native AVPlayer

Source media (for playback bugs)

No response

Error codes / log lines


Anything else

No response

Activity

  1. added
    bug
    on Sep 25, 2026
  2. ijuniorfu commented on Sep 25, 2026

    @ijuniorfu
    Author

    Wouldn't it be better if PGS decoding didn't run on the main thread?

  3. superuser404notfound commented on Sep 25, 2026

    @superuser404notfound
    Owner

    Thanks for the profile, it pointed straight at the problem. Merged in #635 (875acefc) on main, not in a release yet.

    Your reading was right: bitmap decoding ran on the main thread. Two parts to the change:

    • The decode is off the MainActor now. The overlay drainer plans and applies its results on the main thread and decodes in between on a background task. The PiP/AirPlay OCR worker was decoding the same packets a second time on the main thread; it now decodes off it too. The biggest batch came right after a subtitle selection or a seek, when the drainer backfills roughly 75 s of content in one go.
    • The bitmap conversion is about 4x cheaper. imageForSubtitleRect walked the full 1920x1080 plane pixel by pixel twice (crop bounds, then RGBA). It now resolves the palette once into a lookup table. Output is byte-identical.

    Measured on an M1 with a full-canvas 1080p PGS set (the Blu-ray remux shape):

    build before after
    release 5.1 ms 1.3 ms
    debug 215 ms 52 ms

    One question: was the Time Profiler run on a Debug build of your app? Xcode builds Swift packages unoptimized in Debug, and that is roughly 40x slower on this loop. A Debug build fits your numbers much better than a Release one.

    If you can re-run the same file against main, a before/after from your side would be great.

  4. superuser404notfound commented on Sep 25, 2026

    @superuser404notfound
    Owner

    Released in 7.17.0 (875acefc). Bitmap subtitle display sets are now expanded off the main thread, both in the overlay drain and in the PiP/AirPlay OCR worker, and each bitmap is about 4x cheaper to convert. A retest on the title that showed the high CPU would settle it.

  5. ijuniorfu commented on Sep 25, 2026

    @ijuniorfu
    Author

    Thank you very much; it seems to be resolved. I'll let you know once I'm able to test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions