It's on demand (afaik) as you scroll through your feed... so it connects and disconnects very rapidly based on what needs to be displayed. My number of relays sometimes jumps to 1500 and then down under 200 again.
So essentially this is leveraging the fact that you usually follow only at most thousands of people and also the fact that you can only view a small number of pieces of content at the same time on your screen. And then finally, some relays are actually shared / used by multiple people, so the number of relays that you practically need to pull from stays similar no matter how many people you follow.