简体   繁体   中英

Why does Qt Webassembly app start too long?

I am checking the examples (QtQuickControls 2.0) with QT Webassembly (6.3), and it takes too long to load the app in webbrowser over LAN, especially on smartphones compared to the laptop. Too slow is around 40 seconds. Most of the time as I can see on the screen it is "Compiling".

  1. What is "compiling" in this case? I thought webassembly code is already compiled and just needs to be run.
  2. Is QT Webassembly app always slow like this? Is there any means to make it load faster? At least load for the first time, then run it from cache, as now it spends the same much time to reload the app if page is refreshed.

I have checked the Felgo demo apps (I hope they are pretty much polished), but on my smartphone it takes around 20-30 seconds to load for the heavy example. https://felgo.com/try-wasm/

The "Compiling" in this case refers to the WebAssembly.compile() that the qtloader.js internally calls. This basically loads the WASM binary code into the web page.

According to the comments in qtloader.js default template, the "Compiling" is displayed when a fallback is used. Normally it should say "Downloading/Compiling" which is the faster method.

  return WebAssembly.compileStreaming(response).catch(function(error) {
      // compileStreaming may/will fail if the server does not set the correct
      // mime type (application/wasm) for the wasm file. Fall back to fetch,
      // then compile in this case.
      return fetchThenCompileWasm(response);
  });

So check if the mime type is set correctly as the comment suggests.

The second option to improve performance is to enable gzip compression in your web server settings. The WASM files compress quite well, in my test for example a 13 MB file was compressed to 5 MB. This will make the otherwise quite large download a bit faster.

But even after all the optimizations, the Qt for WASM must still download and load a full Qt GUI framework and this will take time. On my Android phone, a smaller WASM GUI will load in about 3 to 4 seconds on local network but this very much depends how powerful the device is (I tested withCDP Browser WASM GUI which is basically a QTreeView showing some data).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM