Top

I used to encounter a bug in youtube website a couple of years ago. In this article, I'm going to talk about a possible cause of that bug.

I believe this bug slipped past the QA because it only manifests itself when you're on a flaky 2G connection (<50kbps), and apparently all the web developers/testers use a 1GB connection with 5ms ping, that never disconnects.

However, I have to say that youtube webapp is one of the highest quality websites I've seen. Its keyboard controls are better than any other streaming platform.

The bug

The bug was that if you were watching videos at 144p (which is the only option at that bandwidth), and the network disconnects, after the reconnection, the quality setting on the video changes to the highest quality. The cause of this bug is obvious if you know that the youtube backend is written in python.

The cause

In python, you can index an array with a negative number to index it in reverse.

>>> a=[144, 240, 360, 480, 720, 1080] >>> a[0] 144 >>> a[-1] 1080

I think what used to happen was that I'd select index 0 as my preferred quality setting. The backend would notice that my bandwidth isn't good enough, and decremented my quality setting to -1. Which just caused the video to lag even more.

I think this bug is still there. I remember seeing this bug a couple months ago (I'm not sure). You see, bandwidth isn't the only reason to play videos in lowest quality. Playing HD video takes a non trivial amount of cpu, so I switch the quality on music videos to lowest whenever I'm compiling something.