This was actually a red herring. While the above is slow, the biggest problem is notifying you about descendant comments, but not notifying you more than once if you have more than one ancestor to a reply.
That is YOU1 > someone1 > YOU2 > ... > someone2 ... When someone2 comments, you only want one notification even though it's the descendant of two of your comments, YOU1 and YOU2. In order to make only one notification, I have to take the list of ALL replies to you, then make them distinct which requires hashing every reply to you ever.
As you become a mature user the issue gets worse and worse which is why my notifications are so slow. I need to figure out a hack that prevents me from having to make these items distinct.
Found a hack that reduces the cost from 548089.02 -> 5193.26, 100x improvement ... still need to test, but hopefully that will let us grow another couple months without overhauling notifications.
reply
fascinating to read... there are probably papers out in obscure journals about how to optimize this... i'm amazed how responsive twitter notifications are as such a large scale...
reply
They denormalize them most certainly (lots of data duplication in the data models) which is fast but relatively complex to maintain.
reply