I noticed that Page 14 of "newest questions" seems to always show only half of the questions the other pages do.
So, just out of curiosity … What's up with that, SO devs?
Well, back in the day we used to use direct queries to SQL Server to build up the various question sort pages.
This worked fine for a while, and Smurfs were happy. However, slowly, over time we discovered that for our specific use SQL is just not fast enough.
I posted a question on theoretical CS that touches on the issue: Data structure that allow efficient tag based lookups
Fast forward a few months, and we reimplemented a large amount of functionality we used to depend on SQL Server for, using in-memory structures.
These days, when you click on any tag or combination of tags or click on the top level Newest, Faq, Active, Votes or Featured tabs you hit the TAG ENGINE OF DOOM
This in-memory structure holds all of the information needed to provide the various question sorts and filters in lightning speed.
The Tag Engine contains many optimisations, one such optimisation is the ...
Block size in the query cache
When the tag engine is asked for all the questions on page 14 with page size 15, we cache the results so subsequent queries do not need to traverse the tag engine.
But we are tricky.
Instead of simple caching results numbered 195 -> 210, we attempt to cache blocks of 200.
Since we perform caching in blocks of 200, hitting page 1 of any sort with a page size of 50 wil pre-fetch the next 3 pages.
But there was a bug.
The code that decided how many results we need to pre-fetched, was only fetching results 0 through 200. Somebody (Waffles) forgot to allow for a misaligned block.
I just fixed the engine so it now will fetch 0 -> 400 in the example case.
And there was peace on earth...
or was there... fast forward a few months and we discovered that .NET is freezing our app once every few minutes for about a second, it does not like having so much stuff in memory ... the resolution of this is a topic of another post