The first one looks like an easy optimisation that I think makes sense, @david and @eviltrout spent time optimising this area so I will be very curious to see what they think about it.
The second feels a bit more fragile long term, totally get the desire to optimise but it worries me a bit cause it will be an area we need to maintain.
Hi @rrit - thanks for the PRs. The first one sounds like a good improvement. Were you able to measure the performance impact? How much time does it save?
As @sam said, the maintainability of the second one is a little concerning. It looks like it’s a copy/paste from the Ember source code? Did you change something in order to improve performance?
E.g. renderTopicListItem ultimately triggers many calls of _getPath (another 50-100 ms to save): Firefox Profiler (callstack filtered to _getPath inside renderTopicListItem)
Maybe the expensive calls to _getPath is something to be optimized in Ember.js and not in Discourse.
And check out Firefox Profiler to get some inside on JavaScript execution:
Unfortunately I haven’t been able to replicate this large speed increase. On Firefox and Chrome (macOS) I’m not seeing any measurable improvement. Chrome spends around 23ms in renderTopicListItem. Firefox 30ms. On an older android device (Pixel 3), I’m seeing around 108ms. The numbers don’t seem to change before/after the change.
By the way, I measured these numbers by using the performance API. I added performance.mark("rtli-start") at the start of renderTopicListItem, and then performance.measure("rtli", "rtli-start") at the end.
Then I reload the browser with dev tools closed and browser plugins disabled (dev tools and browser plugins can significantly affect rendering performance). Then after loading is complete, open dev tools and run this to sum up the measurements:
performance.getEntriesByName("rtli").reduce((v, m) => v + m.duration, 0);
We’ll definitely get this change merged - it’s clearly a better implementation. But I’m not sure whether it will give us a visible difference in render performance
My Discourse testing-instance has many topics with many answers and many different authors - data pulled from a productive-instance. This results in lots of elements to be rendered.
Maybe this is the difference in our benchmarks?
Pre-rendering of content below-the-fold
Discourse pre-renders 30 topics on page ‘latest’. Then the content gets displayed for the first time (FCP). Above-the-fold there are only ~12 topics visible.
Same for a topic page: 20 posts pre-rendered, but max of 6 one-line-posts are visible above-the-fold.
This might be another point of optimization for FCP.
Would you mind sharing the Firefox and OS version? The 290ms number is almost 3x slower than a 2018 android device, which is a little surprising.
That may explain some of the difference, yeah. In my case, I ran them using live data from Meta:
bin/ember-cli --environment production --proxy https://meta.discourse.org
Yeah, this is a possible improvement. However, we’ll need to be very careful that the layout and/or scrolling doesn’t jump around (e.g. if the user is refreshing the page when they’re already scrolled halfway down). The definition of ‘below the fold’ also varies based on the device/browser/theme.
Discourse Build Error
Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames:
Host: localhost. is not in the cert's altnames: DNS:*.cdck-prod-meta.discourse.cloud
Discourse Build Error
Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames:
Host: meta.discourse.org. is not in the cert's altnames: DNS:*.cdck-prod-meta.discourse.cloud
System used for benchmarks
Extracted from Firefox about:support
Name
Firefox
Version
95.0.2
Build-ID
20211219102529
Distributions-ID
canonical-002
User-Agent
Mozilla/5.0 (X11; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0
Betriebssystem
Linux 5.10.0-0.bpo.9-amd64 #1 SMP Debian 5.10.70-1~bpo10+1 (2021-10-10)
Betriebssystem-Theme
Adwaita-dark / Adwaita
Anwendungsprogrammdatei
/snap/firefox/777/usr/lib/firefox/firefox
Name
Firefox Developer Edition
Version
96.0b10
Build-ID
20211228195952
Update-Verzeichnis
/opt/firefox-dev-autoinstall
Update-Kanal
aurora
User-Agent
Mozilla/5.0 (X11; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0
Betriebssystem
Linux 5.10.0-0.bpo.9-amd64 #1 SMP Debian 5.10.70-1~bpo10+1 (2021-10-10)