Stalls in document loading were traced back to issues with the long-string handling abilities of Android’s Webview loadUrl method. Implementing an alternative websocket-based approach eliminated the problem.
Everyone wants snappy scrolling and quick loading documents, so a design issue in the Android Webview loadurl method appeared to make the Collabora Online Android app fail to load documents was of critical concern, as it seriously impacted the end-user experience.
A user-reported GitHub issue seemed to indicate that larger documents were failing to load or only load in part. The initial investigation into the problem highlighted that the root of the issue wasn’t that the document failed to load, more it was rendering impossibly slowly, giving the appearance of a load failure. Once the issue was confirmed, it was tagged as a high priority and assigned to our Android developer Skyler to fix.
Collabora Online is available for both iOS and Android devices. To enable the mobile app to function offline or with interrupted or poor network connections it utilises its own local coolwsd – the server that renders and streams image tiles of your documents to the client so they can be viewed and edited. Coolwsd renders the documents being viewed into 256×256 raster tiles, with the original reported implementation these are base64 encoded – to safely transport the UTF8-encoded strings – and loaded by the browser client. This should be a smooth uninterrupted process, which it was not.
Our assigned developer Skyler implemented performance profiling to try and narrow down and locate the issue. The first move was to run testing on iOS to see if it was suffering the same performance issue, it wasn’t, so this appeared to be an Android-specific issue.
The first step in assessing the issue was to devise suitable profiling and debugging. The initial flame graph for the system seemed to indicate that either the system was sending way too many tiles or the tiles that were being sent were taking an age to be processed.
Analysing the browser logs revealed 105,707 tile messages, so there were a large number of tiles being processed but none of them were actually making it to the user’s screen. At this point it made sense to see if it was possible to optimise the situation either through better prioritising or removing duplicate requests, then see if that alleviated the issue.
Further log analysis showed that a whopping 91% of tiles were duplicates. Implementing a patch to remove duplicates still led to an enormous number of invalid tile requests. After testing under the Core and the Desktop versions, Skyler logged to see if tiles were being sent unrequested and they were, alongside a large amount of duplicate tiles.
After investigating the duplicate tile issue, Skyler developed a prototype patch to help reduce the number of duplicate tiles resulting in a reduction in lag, but the rending speed still remained slower than it should.
The actual culprit for the performance hit turned out to be Android’s Webview loadUrl method, which doesn’t like handling very large strings. The encoded tiles have to be passed to the browser in the form of a very large string as part of a Javascript function through a fake websocket. An initial solution was to send anything over 1,024 bytes through a HTTP request with a short message still going through Javascript to the Webview. This led to the final patch set that created an Android MobileSocket, based on the existing ProxySocket – implemented to work around PHP’s timeout limits and situations involving strict firewalls that don’t allow websocket connections.
The most striking way to experience the difference in performance is to watch the before and after videos, which are night and day in performance terms. Delving into the system tasks the main culprit was the WebViewChromium.loadUrl task, this was in effect stuck trying to load tiles until the user gave up on it. The final fix still uses this task, but only for message polling all the tile data goes through the MobileSocket.
The end result is vastly faster document loading when viewed against the earlier releases. You can find the 25.04.2 Android release of Collabora Office, which includes this work, on the Google Play Store.
Download Collabora Office for iOS and Android:
Head over to the docs or start by following our step-by-step instructions and build CODE from scratch.
Working with other hackers on improving Collabora Online is fun and very rewarding! Find out how you can get involved.
Get in touch for a quote, ask a question or sign up to the newsletter so you don’t miss out on all the latest news.
Collabora Productivity Ltd © 2025 All Rights Reserved.