PERF: limit number of posts in topic for very first paint (PR #15579)

First-time visitors from search engines have a high page loading time for topics with many posts.

This tries to fastly show a visitor some meaningful content on the very first page view by only showing 2 of 20 posts plus 18 placeholder posts. When the first two posts are painted and displayed by the browser, then it immediately starts rendering the other 18 posts.

After discourse is fully loaded it does not interfere with any subsequent topic views anymore.

GitHub

It’s a nice idea, but I think it’s going to be very tricky to pull off reliably, and without making the layout jump around. For example, what happens if the user if following a link to a specific post which is very far down a topic? e.g.https://meta.discourse.org/t/183261/205 or https://meta.discourse.org/t/183261?page=2

rr-it:perf/fcp-post-stream-limit

I have in mind to handle each situation when the layout might jump around in it’s own way to make it more appealing.

  • topic-view is entry-page and 2 posts don’t fill full viewport height → use this feature and show placeholder-posts which get replaced by real posts.
  • topic-view is entry-page but has deep-link to posts far down in post-stream - e.g. the non-regular visitor from search engine → disable feature and let the user wait for a correct first paint like before.
  • topic-view is not entry-page - user switches into topic from an already completely booted Discourse → disable feature and let the user wait for a correct first paint like before.

I agree with @davidtaylorhq that there are a lot of issues to sort out before we could consider merging this.

  • It would have to work with every kind of topic we support, and all major plugins
  • It has to support deep linking, cloaking, upwards and downards scrolling.
  • It would have to show a meaningful performance benefit. 10ms is probably not worth the additional complexity for example. How much time are we talking about here?

This is a tremendous amount of work, and I’m not sure it’s worth the benefit.

I think a draft of this is premature. If this is a path you want to take, and are confident you could fulfill all the above obligations I recommend you do it outside of our tree and present it when it’s more complete.