8 min read #OpenCloud#Tech

OpenCloud · Performance

WebUI performance from 1.5 to 0.9 seconds

Between rolling releases 5.1.0 and 8.1.0, the OpenCloud web team made the web interface faster in many places without removing any features. Thumbnails load at the size they are displayed, a selection only redraws the affected rows, and on startup the browser loads only the font and the language it needs. According to the release notes, the first content now appears 40 percent sooner, after 0.9 instead of 1.5 seconds. The gain is largest on slow devices and weak connections.

Whether a web interface feels fast is rarely decided on the machine it is developed on. That machine has a current processor, plenty of memory and a good connection to the test server. Every unnecessary request only becomes noticeable on an older laptop, a budget smartphone or on a train with a weak mobile connection. OpenCloud wants to make collaboration possible regardless of budget. That includes an interface that responds in reasonable time on devices like these.

The work stretched over roughly eight months and about twenty pull requests, with no big rewrite. Many of the changes follow the same three rules: load only what is visible, redraw only what has changed, and request images at the size they are displayed. Where measurements exist, they are in the pull requests and issues.

Lazy loading for previews and tiles

The preview app came first, in February (5.1.0). In large photo folders it requested images at full resolution, including for the filmstrip along the bottom edge. Since then, only the image currently shown loads in high quality. The filmstrip gets small thumbnails, and only for the entries inside the visible area. If you flip through images quickly, pending requests are canceled instead of continuing in the background. That takes load off the browser and the server, especially on slow connections.

The same principle helped the tile view in 7.4.0. When a folder opened, it computed the link for every single file, including those far below the visible area. According to the issue, a folder with 250 files took one to two seconds. Now links are created only for tiles in the visible area.

Fewer re-renders in long lists

Also in 7.4.0, the team addressed a delay that showed up with as few as a hundred files: selecting a single file meant a noticeable wait. The reason was that the selection was passed to the entire table as a list of IDs. Every change therefore redrew all rows and re-ran helper functions for each row. Today each row reads its own selection state from the store and only redraws when that state changes. Whether a file is selected is answered by a single lookup in a Set instead of a search through an array. The tile view got the same change.

For very long lists in the admin settings, the problem was elsewhere. The “Items per page” setting is read asynchronously from the URL and was not yet available on the first render. At that moment the pagination returned the entire list, around 90,000 DOM nodes for 6,000 groups, before switching back to 50 entries. With a default value for that moment, the list's load time in the pull request's measurement dropped from 5,172 to 509 milliseconds. In the user list, the interface now loads users, groups and roles in parallel and no longer fetches group members, which were not displayed there anyway. As a result, the group filter opens after 25 instead of 1,219 milliseconds with around 6,000 users and groups. The lists of shares, space members and group members in the sidebar are now paginated as well.

Right-sized thumbnails

Shortly after 7.4.0, a community user reported that scrolling in a folder with more than 550 entries had become sluggish in Safari. The analysis turned up several causes. Every tile requested its thumbnail at 1000 × 1000 pixels, about 816 KB in size and about 4 MB in memory once decoded, for an area of 316 × 178 pixels. With 500 tiles, that added up to around 400 MB of image data. None of it was released, and the cache held 250 entries, so on a page with 500 entries the second half pushed out the first. In WebKit, the average frame time was 80 milliseconds, and 32 with thumbnails blocked.

The fixes came in 7.5.0. Since then, the thumbnail size depends on the actually rendered tile and the screen's pixel density. Pixel density counts with a factor of at most 1.5, and no thumbnail is larger than 768 pixels. So that the server can deliver matching sizes, the thumbnail service knows additional default resolutions between 128 and 1,080 pixels. Before, there was no step in between. According to the pull request, this makes tile thumbnails about eight times smaller. If you have set THUMBNAILS_RESOLUTIONS yourself, you don't get the new steps automatically and should check your own list.

The cache now measures its size in bytes instead of entries, with a budget of 150 MB. Evicted entries release their memory. Thumbnails still in the queue when their tile scrolls out of the visible area are discarded, and the browser decodes images asynchronously without pausing the scroll.

Two more findings followed in 8.0.0. Every list entry had its own IntersectionObserver, so 500 of them in a folder with 500 entries. Now they all share one. According to the pull request, though, the main cause of the problems in Safari were CSS classes using the :has() selector in the bulk actions area, which Safari handles poorly. Since they were removed, the reported issue is considered fixed. According to the release notes, tiles and thumbnails in a folder with 1,000 photos now hold up even under fast scrolling. The issues do not give measurements after the changes.

Code splitting and smaller bundles

For a long time, how long the interface stayed blank after you opened it depended on things that aren't needed for the first screen at all. In 6.2.0, the team split large JavaScript bundles and made several startup requests run in parallel instead of one after another, including the WebFinger lookup and the capabilities. On a throttled “Slow 4G” connection, load time in the developer's measurement dropped from about 16.4 to 14 seconds.

Four changes came together in 8.1.0. The editor with ProseMirror and highlight.js only loads when someone opens it. The largest bundles are split further, the Files app bundle for example from 880 to 260 KB. The Inter font now contains only the weights actually used, 400 to 700, and is split by script. Only the Latin subset is preloaded, at 48.5 KB instead of the previous 337.5 KB file; Cyrillic or Greek follow when needed. And translations now load only for the selected language: German loads 34 KB instead of 419 KB (gzip), English loads nothing at all, because the strings in the code are already English.

The same request for the file view, OpenCloud 7.4.0 on the left, 8.1.0 on the right, both with an empty cache and throttled to the DevTools profile “Slow 4G” in Chromium. Shown from second 8 onward. In this measurement, the files were visible after 12.9 and 11.1 seconds respectively; 8.1.0 transferred 0.96 instead of 1.70 MB, the Inter font 50 instead of 346 KB (local test instance, demo data).

The pull requests include Lighthouse measurements for each step. They don't state the conditions under which they were measured, and the values don't line up exactly from one step to the next:

ChangeFirst Contentful PaintLargest Contentful PaintLighthouse score
Bundles split (web#3378)1.5 → 1.3 s2.1 → 1.8 snot stated
Font split (web#3500)1.3 → 1.1 s1.9 → 1.7 s88 → 92
Translations per language (web#3522)1.0 → 0.9 s1.7 → 1.3 s92 → 96

The release notes sum this up as 40 percent faster first content (1.5 to 0.9 seconds), 35 percent faster full page (2.0 to 1.3 seconds) and a Lighthouse score going from 85 to 96.

On a fiber connection, a few hundred kilobytes hardly matter. Over a weak mobile connection or on an older device, they decide whether you see something after opening the page or stare at a blank screen. Many of the bugs only showed up with realistic amounts of data: 250 files in the tile view, 6,000 groups in the admin settings, 500 photos in Safari. With a handful of test files, they go unnoticed.

Sources