-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
asset://
protocol does not release the memory properly
#2952
Comments
|
convertFileSrc
method does not release the memory after not being used.asset://
protocol does not release the memory properly
Untitled_.Nov.30.2021.7_49.PM.mp4Not sure if I recorded the correct one but what I'm sure is the memory rocketed after I use |
Looking at your video, I think it is the rust process that doesn't release the memory correctly. we surely need to investigate this further. thanks for helping.
Again, just for clarification, |
Ah okay, thanks for your explanation, anything it is, it'd be better if there's any function to release the memory. Also, thanks a lot |
I think the problem is on wry's response (https://github.com/tauri-apps/wry/blob/b300e7ac3da481b12fe5bc6559e06c0f3a0bf794/src/webview/webview2/mod.rs#L431). cc @wusyong @lemarier @amrbashir |
The issue is most likely caused by Webview, and Chromium in particular. I see the same issue in my Electron file manager app. In my case (and probably yours as well) the issue is caused by Chromium's GPU process. It usually takes ~200 - 500 MB of RAM to decode a video. Chromium caches the whole video in memory, so even when the source is gone from the drive, the video will keep playing, The only solution I found for this is to run the app on a dedicated GPU, which offloads decoding and the decoded data to the dedicated GPU's memory. In my case the RAM usage drops significantly (I didn't push the feature to Github yet). |
Someone on Discord also reported it (probably for the tauri protocol this time): https://discord.com/channels/616186924390023171/731495028677148753/918999569818337340 |
Erm, any idea to fix it on Tauri? |
Not yet, we're still trying to see where it is happening (maybe it's chromium?). |
Okay, please lemme know if there's any workaround, thanks a lot! |
@lucasfernog I tried several methods to create IStream (SHCreateMemStream, CreateStreamOnHGlobal, ...) and I'm pretty sure they are released properly. |
@wusyong on MacOS, Linux you can run the app with --force_high_performance_gpu Chromium flag (not sure if it will work on Tauri) On Windows, I'm switching to high performance GPU by changing a registry value, like this: let deviceNumber = 2
let registryPathGpuPrefs = 'HKEY_CURRENT_USER\\Software\\Microsoft\\DirectX\\UserGpuPreferences'
let appBinPath = electron.app.getPath('exe')
let command = `[microsoft.win32.registry]::SetValue(\\"${registryPathGpuPrefs}\\", \\"${appBinPath}\\", \\"GpuPreference=${deviceNumber}\\")`
require('child_process').exec(`powershell -command "${command}"`) |
@aleksey-hoffman Thanks for the quick reply! I'll see if it can work in our case! |
Looks like its sort of a bug inside webview2 |
Having same issue with asset protocol causing memory leak with webkit on
|
Thanks for the report @tedbyron I just opened a wry PR to fix that issue. |
@lucasfernog Seems that your wry PR is merged? Any idea when we will see this fix in the latest version of Tauri? Or is it something that still needs to be fixed upstream in the Edge Webview2 itself? |
We just published it but there's still some upstream issues. |
Yeah, I was worried that was the case :/ |
That PR was specific to macOS |
Has anyone here found a workaround in the mean time? Maybe a different custom protocol, or a chromium flag to allow loading the videos directly from |
Looks like this applies not just to the I tried a workaround by following the "custom streaming protocol" example from the Tauri repo here: https://github.com/tauri-apps/tauri/tree/dev/examples/streaming. The only change I made was replacing the "big_buck_bunny.mp4" video with a different 2GB video. After causing the video to buffer a couple times by seeking to different times in the video, the RAM usage climbed to 8GB+ (4 times larger than the video I was loading). Shortly after this screenshot it maxed out my system's memory and bluescreened the computer. I'm assuming that the root cause here is still the same upstream Edge Webview2 bug. Since they have a 4-week release cadence, and their last update was yesterday, I'm guessing it will be at least a month until this might be fixed :/ |
FYI someone started looking into the webview2 issue yesterday: MicrosoftEdge/WebView2Feedback#2171 (comment) |
Ok, that is good to hear 🙌 |
Looks like this has been fixed! See: MicrosoftEdge/WebView2Feedback#2171 (comment) Now...how do we go about making sure the fix is included in our Tauri app? |
We unfortunately have to wait for it to be part of the stable channel. Once it is, it should be automatically deployed to all tauri users (both, devs and end-users alike). |
Idk how the canary is distributed but you might be able to use the fixed runtime config option: https://tauri.studio/v1/api/config#windowsconfig.webviewfixedruntimepath |
webview2 104 was release a couple of days ago and some people reported that the leak was indeed fixed 🥳 Please reach out to us if you still notice leaks even after upgrading to 104 (should have happen automatically) |
I have webview2 104 installed and I see a memory leak on loading and playing a video file using the |
I am still seeing memory issues with this as well. I can possibly provide examples if needed. |
Dang, I thought this was fixed. I'm still getting memory leaks on video playback through the asset protocol. Steps to reproduce:
App hard crashes to desktop, killing the inspector, the Webview window, and the Tauri CLI process. The solution I'm currently using is bundling a localhost server with my app to handle loading local videos. |
I don't think this is caused by leaking. Asset protocol will return whole data no matter what headers from requests might have. |
Ahh, you're totally right. It's not a memory leak, it just returns huge chunks of data at once, gigabytes or more. Thank you for the clarification and example, this helps a lot. |
@nathanbabcock were you able to get past the crashing using the example? We're also having the issue and would love a way to resolve it. |
@ksumarine I did not revisit the streaming example, I reverted back to a localhost server I had set up previously. It's basically the same thing though. If it helps you as a reference I'll put it in a gist: https://gist.github.com/nathanbabcock/c819ff70803c70708687196b4fe658ac There's a little more in there than strictly necessary, for security purposes, like restricting the mime type and requiring an access token. If I were starting from scratch today, I would try the streaming example again and use the built-in security settings inside of |
@nathanbabcock this is great, thank you for providing it! Looks like I'll be doing something similar for our app |
@nathanbabcock @ksumarine looks like you are facing this issue #6375 which is already fixed in a PR and waiting for merge |
Yes, that does look like the exact issue we're facing! Thanks for your work on this @amrbashir. |
@amrbashir that's fantastic. Thank you! |
Describe the bug
The
convertFileSrc
method does not release the memory after not being used.To Reproduce
Steps to reproduce the behavior:
Expected behavior
There is a function to release the memory/automatically release that after the src no longer exists on the DOM. The first method will be preferred tho.
Screenshots
Here's a screen record in which hundreds of MBs of RAM are gone.
Untitled_.Nov.24.2021.6_17.PM.mp4
For the Downloads folder, there're video files, this makes the memory bump into 500mbs (including the hundred mbs of the basic layout), but no release after not using it
Platform and Versions (required):
The text was updated successfully, but these errors were encountered: