Improve playlist sorting stability and performance#13
Conversation
…handling of auto-scroll and video tracking across rerenders
|
I'm so sorry about the lack of replies or accepting this PR. Do you wanna just take over the development for now or just have me merge the code? I can piint to your fork specifically if you wish, I clearly don't have the time or will to maintain this specifically |
|
I would be wary of accepting this without more tests; it smells heavily of AI, and when I tested it, I noticed no actual functional or performance improvements. The code changes feel like someone asked an agent "improve this" and this PR was the result. The most recent version of the script is still working fine. |
No worries. I'd rec doing a few more tests like @MobyGamer said before merging, imo, I've only tested this against Watch Later playlists sub <150 videos. I'm not sure how it performs on playlists of extremely large sizes like 300 or 400. I also don't really have much time to maintain the project either, but I thought I'd atleast contribute because the old method was way too slow for my tastes. My biggest issue was that when my Watch Later playlist got to around 90ish videos, it'd struggle to load the DOM and sort. |
The most recent version is working aceptable enough, but it does fail at times. Im genuinely surprised you didnt notice any functional improvements. I've been petpeeved for months because the tool would struggle to sort on larger-sized playlists, either completing failing to sort or just be very slow. The previous implementation would track items by their positions and element references, then performed a sequence of drags/swaps based on those original positions, but then YouTube would rerenders/rebuilds the playlist rows after drag-and-drop, breaking the sort often if it couldnt properly load the new DOM (Common on larger playlists). The most critical addition to this PR was that the new implementation precomputes the sort order before sorting, thus eliminating the care for any rerendered DOMs as its sorting. Which also ends up making it complete sorting faster. What were your test conditions? |
The same number of items as your tests, but after some consideration, I think my situation is not appropriate for performance testing. I run on a very performant rig, and I also have fast bandwidth with very low latency. My results are likely not typical for that of the average user, so I think some more testing is prudent. (I sometimes run the script as fast as only 200ms in the delay field without trouble.) |
Summary
This PR refactors the playlist sorting logic to make it more deterministic, faster, and resilient to YouTube’s dynamic DOM behavior during drag-and-drop operations.
YouTube frequently updates and rerenders the playlist DOM during drag operations.
The previous approach relied heavily on static positions, which could lead to:
This update ensures the script remains accurate and consistent even under those conditions, while also improving sorting speed, resulting in:
Key Improvements
Stable video tracking
Deterministic sorting algorithm
Improved performance
Increased reliability
Robust duration parsing
mm:ssandhh:mm:ssformatsAuto-scroll fix
I've tested this several times against a variety of Watch Later playlist conditions from small (10-20 videos) to large (100+) playlists, with unavailable videos, etc. So far, so good. Changes are stable.