Aakash Howlader
All writing

Why XFlog stopped loading the whole timeline

An XFlog performance benchmark on the same 1,000 saved X events. See how incremental loading cut the All saved wait even as the full API read got slower.

A strip of punched stars unwinds from a spool and passes through a small viewing gate.

In my last post about the timeline, I was quite happy that All saved finally loaded all the pages. There was a bug where XFlog would show the first 25 events and leave the rest in the database. Follow the cursor until it runs out. Fixed!

Well, try that with 1,000 events.

XFlog 1.0.10 made 40 timeline requests before I could use Constellation in that range. It got 25 records at a time, put the pages together, and drew a star for each action. That last bit was the whole point of the earlier fix. If someone followed, unfollowed, then followed again, I wanted to see all three. If those were the only three I cared about, tough. The browser still had to get through all 1,000.

On the same saved history, 1.0.16 got the timeline ready in 61 ms instead of 2.23 seconds. Those are the medians for switching from 24h to All saved. It took one request to draw the first 50 stars and tell me there were 1,000 events in the range.

The fun bit? Reading all 1,000 through the API actually got slower in my run.

Forty requests to look at a star

The old browser code already had pagination. That’s what makes this a little silly. I had the pieces for fetching one page at a time and was using them in a loop that finished before the timeline rendered. Even if I only wanted to look at the newest event, the browser still had to wait for a response with no next cursor.

In 1.0.12, the timeline started asking for the newest page and the saved total. All saved still covers everything in the selected history. The counter can say 50 of 1,000 events loaded, and Load older activity gets the next page. In the 1.0.16 run that next click took about 65 ms to take the browser from 50 to 100.

There are two numbers I care about here. One is how many records exist for this range and filter. The other is how many I have in the browser. I can show the first from the database without hauling over all the events just to count them in JavaScript.

This also means the browser has to take care of the cursor it got. The newer timeline pages against a saved snapshot, and the cursor carries the scope of the query it came from. A live update can add a new row while I’m looking at an older one. If I change the filter, I need a cursor for that filter. If I stay where I am, the older-page cursor still has to let me get to the older records. Otherwise we’ve just traded a long wait for a list that occasionally skips something. That would be a worse deal.

So, did the queries get faster?

I had already blamed Gradio once before looking at how much of the frontend was my own JavaScript. Here there’s another easy conclusion to jump to. The interface is much faster. Maybe the database query got much faster too?

Well, I asked both APIs for 50 events. Then I followed the cursors through the whole history, using pages of 50 on both sides. Same 20 requests. The runner checked all 1,000 event IDs in order so I’d know if one of the versions had conveniently left a few out.

Local benchmark, median of five runs 1.0.10 1.0.16
Switch to All saved in Constellation 2,230 ms 61 ms
Requests before that view was ready 40 1
Events loaded at that point 1,000 50
API first page of 50, including JSON decoding 4.24 ms 5.89 ms
API read and decode all 1,000 in pages of 50 83.82 ms 91.27 ms

Yep. 83.82 to 91.27 ms for the full API read. A little slower in the newer version on this fixture. The ranges overlap across runs. The first response is also a little bigger, 20,951 bytes versus 20,538, and carries the aggregate metadata. I’d need to profile the server to say how much time each operation takes. The table tells me what the caller waited for.

The browser numbers measure what each release actually does when I choose All saved. The API numbers keep the page size and record count equal. I can get to the first star sooner because I only need the first page for that. Reading every event is still work I can ask it to do, a page at a time.

For the fixture I used 1,000 synthetic events from 400 actors: 600 follows, 200 unfollows and 200 replies. Fifty were in the last 24 hours. Both tags started with byte-identical copies of the SQLite file and ran on the same i7-12700F desktop with headless Chrome 157 on loopback. Five measured runs each, after a warm-up, with alternating order. Tracking was paused and the test transport rejected provider requests. If you’re curious about the timings or want to run it yourself, the benchmark runner and raw results are in Git.

Fifty events and eight Journal rows

I also switched to Journal with the same 50 events already loaded. The old Journal mounted all 50 rows. The new one mounted eight in my 1280 × 720 browser window. As you scroll, it renders the rows near where you’re looking and keeps the scroll position and focus when older records arrive.

Was switching layouts much faster? 43 ms versus 40 ms at the median. I wouldn’t make much of that difference. Seeing eight rows mounted tells me exactly what the virtualization changed, and I’d want a longer scroll test before putting a smoothness number on it.

Even the normal 24-hour open was fairly close. 272 ms versus 244 ms with the same 50 records, and the run ranges overlap. That makes sense. There were only 50 matching events for either version to get through. The wait I was fixing showed up when the range got bigger and the old loader decided that it needed everything before it could draw anything.

Okay, but where did Mentions go?

This was the bit I cared about after paging the timeline. Suppose Mentions has saved events, but all of them are older than the first page. I zoom out to the Activity overview. Should Mentions be there? Of course. So I click it. Can I open it without scrolling through old follows first?

The overview needs the group totals even when it has zero rows for that group in the browser. Once the totals are there, the click can ask the local database for the first page of Mentions. If I’ve already got a mention in the loaded history, the group can show it immediately while its own page comes in. Load older activity then continues through Mentions. And when I click All groups, I want to go back to where I was, with the pages I had already loaded. Going back to the first 50 would be rather annoying after all that scrolling.

That took a few patches, through 1.0.16. I didn’t time the group clicks. The XFlog changelog has the changes by release.

The larger 5,000-event experiment didn’t make it into the table either. I stopped the old browser run while it was still busy rendering. I don’t have a time for that one. Both versions finished at 1,000, so that’s the run I can actually compare.

Anyway. All saved used to mean I had to wait for it to go and get all the pages. Now I can open it, find the event I wanted and leave the other pages in SQLite until I need them. I think I’ll keep that. 😄

Keep reading

All writing

Software. Football. Heavy metal.

Aakash HowladerSame person. Different playgrounds.