tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] Transfer rate from backend is very slow

Open Anglebrackets opened this issue 3 years ago • 8 comments

Describe the bug

First, I apologize if this would not actually be considered a bug, as it is a performance issue. But it was so bad that it made me think it was a bug at first.

Loading a 148MB .gif file took 194987.2ms (3.2 minutes). (Linux on Ryzen 7 5800u 16GB). One core on my machine was at 100% @4.4 GHz the entire time. This works out to about 1.3MB/s transfer rate. During that time, the window was hung -- could not even get to development tools.

I originally came upon the problem using a custom protocol handler, so I know that reading the file into memory took almost no time; it was all transfer time.

I don't have exact times for the release build, since I can't use development tools, but it was comparable timing. (And after updating to rc11 from rc07, I can no longer build the release version with this large file in it.)

For comparison, NW.js (which I'm porting from) loads this in less than 2 seconds. Brave browser with 100MB/s internet also loads the file in about 2 seconds.

All in all, I am loving Tauri, and this doesn't really affect most assets. But I thought you should be aware of the issue.

Reproduction

  1. Start a new project with: yarn create tauri-app

  2. Use this index.html:

<!DOCTYPE html> <body> <img src="Mghhw6X.gif"> </body>

  1. Put this file in dist (it's too large to post to github): https://i.imgur.com/Mghhw6X.gif

  2. yarn tauri dev

Expected behavior

Mghhw6X.gif should appear in window in 2 -3 seconds.

Platform and versions

cargo tauri info

Environment
  › OS: OracleLinux 11.0.0 X64
  › Node.js: 12.22.5
  › npm: 8.10.0
  › pnpm: 6.11.0
  › yarn: 1.22.15
  › rustup: 1.24.3
  › rustc: 1.60.0
  › cargo: 1.60.0
  › Rust toolchain: stable-x86_64-unknown-linux-gnu 

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.9
  › @tauri-apps/api [NPM]: 1.0.0-rc.5
  › tauri [RUST]: 1.0.0-rc.11,
  › tauri-build [RUST]: 1.0.0-rc.9,
  › tao [RUST]: 0.8.5,
  › wry [RUST]: 0.16.2,

App
`tauri.conf.json` error on ``: Additional property '$schema' is not allowed

Stack trace

No response

Additional context

No response

Anglebrackets avatar May 24 '22 01:05 Anglebrackets

Alright, the reason for this is rather simple. Every file in your distDir will be compiled into your executable (not a file, but data in the binary) to help with that, we're compressing every file before including it, decompressing it when the file is requested. I can imagine that taking quite a while. That said, you being on Linux might make things worse, since on my macbook pro m1, the gif loads in 3.4 secs.

Edit: Sidenote: You might want to use the gif as a resource instead. (Or use an .mp4 file, since afaik range requests are supported for those)

JonasKruckenberg avatar May 24 '22 09:05 JonasKruckenberg

Ok, except I see the same timing when loading an external fie from disk using a custom protocol. Reading the file into memory takes minimal time, but the transfer takes 3 minutes.

Anglebrackets avatar May 24 '22 19:05 Anglebrackets

Just to be clear, my goal is to browse arbitrary images on the user's computer. Including it in the build was just a simple way of demonstrating the issue.

In the end, I'm using an embedded Tide webserver to serve external files. Here is the timing: release build, custom protocol handler: 175s release build, Tide localhost server: 1s

In the attached sources, I've included both implementations. Simply change index.html to refer to the file on your local machine.

This is 175x slowdown to use the custom protocol, so I'll be using the local server for my app.

tauri-test.zip

Anglebrackets avatar May 28 '22 22:05 Anglebrackets

Similar problem here. Tauri appears to be 200x slower than Electron loading the same file.

samhippo avatar Mar 03 '23 21:03 samhippo

Chiming in with the fact that I switched https://github.com/mikedilger/gossip from Tauri to egui back in December after a week of failing to debug or work around the tremendously slow performance surrounding transferring an updated vector of hashes to javascript. I didn't understand how to debug it. So I switched to egui and it was instant. Never looked back.

mikedilger avatar Mar 03 '23 22:03 mikedilger

I have a similar problem, working on a project with a friend, for me, it takes more than 1 min to download a 25Mb PNG, but for my friend only 2ms, also reloading the UI during dev sometimes takes like 15s to load with a white screen and for my friend merely half a second.

tauri 1.2.2

MrMarble avatar Apr 07 '23 14:04 MrMarble

I also have a similar problem,transfer 23mb file take about 10s,is serialization of binary data causing this issue?

Xiaobaishushu25 avatar Nov 05 '23 07:11 Xiaobaishushu25

"During that time, the window was hung -- could not even get to development tools." It's strange because I've been trying to problem solve an issue with users locking up upon receiving large quantities of JSON data from the core's listener. Both similar hardware, but Intel vs AMD on Windows. Personally far better performance on my own Intel system, but I don't know if you can chalk it down to that at all, but my only lead on this issue is hardware.

As soon as I adjust my Windows process priority to high/realtime the issue becomes far less pronounced and I get far more stable performance between the webviews and tauri. Making about ~100MB transfer in a second or two. 5MB across 20+ windows with only some jittery framerate on windows, no lock ups.

Very odd. I am hoping this resolves the issues with the userbase on this issue.

Sorry for no benchmarks or technical info, but I thought I'd share what I've found.

ECHibiki avatar May 13 '24 22:05 ECHibiki

+1

Just loading image (6.2MB) from an external source takes forever , compared to the browser.

Anything we can do?

FutureExcited avatar Jun 08 '24 12:06 FutureExcited

+1

Just loading image (6.2MB) from an external source takes forever , compared to the browser.

Anything we can do?

you can try tauriV2( https://github.com/tauri-apps/tauri/issues/9322 )

Xiaobaishushu25 avatar Jun 08 '24 12:06 Xiaobaishushu25