Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Transfer rate from backend is very slow #4197

Open
Anglebrackets opened this issue May 24, 2022 · 10 comments
Open

[bug] Transfer rate from backend is very slow #4197

Anglebrackets opened this issue May 24, 2022 · 10 comments

Comments

@Anglebrackets
Copy link

Anglebrackets commented May 24, 2022

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

@JonasKruckenberg
Copy link
Member

JonasKruckenberg commented May 24, 2022

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)

@Anglebrackets
Copy link
Author

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
Copy link
Author

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

@samhippo
Copy link

samhippo commented Mar 3, 2023

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

@mikedilger
Copy link

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.

@MrMarble
Copy link

MrMarble commented Apr 7, 2023

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

@Xiaobaishushu25
Copy link

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

@ECHibiki
Copy link

"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.

@FutureExcited
Copy link

+1

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

Anything we can do?

@Xiaobaishushu25
Copy link

+1

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

Anything we can do?

you can try tauriV2( #9322 )

kwaroran added a commit to kwaroran/RisuAI that referenced this issue Jul 1, 2024
It's a known issue that IPC call in Tauri V1 is slow
(tauri-apps/tauri#4197) Specifically,
writeBinaryFile can take several seconds if the file is around like 10
MB because of some internal serealization bottleneck of Tauri. This is
really bad as we use writebinaryFile every second to save database.

This PR just create separate http server only handling the bottleneck
part: writebinaryfile of database.bin and assets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants