Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: bbf46ab941a84a573ad4b742e35bda3b698c374c
      
https://github.com/WebKit/WebKit/commit/bbf46ab941a84a573ad4b742e35bda3b698c374c
  Author: Jer Noble <jer.no...@apple.com>
  Date:   2025-08-29 (Fri, 29 Aug 2025)

  Changed paths:
    A PerformanceTests/Media/VideoElementAddManyTextTracks.html
    M Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp

  Log Message:
  -----------
  [Cocoa] Adding many text tracks to a video element is extremely slow
rdar://147072548
https://bugs.webkit.org/show_bug.cgi?id=298122

Reviewed by Eric Carlson.

When TextTracks are added to a video element with its controls enabled, the 
controls ask
for the current available TextTracks to be sorted, and that sort operation is 
of course O(n^2).
In the sort algorithm itself, the same properties are re-calculated many times, 
multiplying
that inefficiency.

Rather than re-calculating the properties needed by the sort algorithim for 
each comparison,
generate a side data structure initialized with pre-calculated values. There's 
still an O(n^2)
complexity to the sort, but the algorithm now just compares bools and strings; 
the cost is
now mostly linear with the number of tracks.

Added a performance test to validate this fix. The perf test adds 60 caption 
tracks and measures
the amount of time taken before all these tracks "change" events fire. On this 
change, the median
time requried to complete each iteration has dropped from 1.30s to 200ms; a 6x 
speed increase.

* PerformanceTests/Media/VideoElementAddManyTextTracks.html
* Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::trackDisplayName):
(WebCore::CaptionUserPreferencesMediaAF::displayNameForTrack const):
(WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu):
(WebCore::textTrackCompare): Deleted.

Canonical link: https://commits.webkit.org/299347@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to