You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I analysed the code of tauri because I wanted to improve the performances of the invoke function (on my project, it takes 30s to read 500Mb of data with a call to invoke while simply reading and writing it in JSON takes only 5s).
From what I understood by reading the code, here is what happen when we call the invoke function:
The Rust function is called [tauri-macros/src/command/wrapper.rs:158]
Its output is serialized as a serde_json::Value [tauri/src/command.rs:197]
The serde_json::Value is serialized as a Json String [tauri/src/api/ipc.rs:69]
The Json String is converted to RawValue, potentially copying all the String in memory [tauri/src/api/ipc.rs:70]
The RawValue is converted to an escaped String [tauri/src/api/ipc.rs:85]
The escaped String is put in a larger JS callback function String [tauri/src/api/ipc.rs:174]
The String is evaluated in JS [tauri/src/window.rs:1289]
I think that three serialization is overkill, the serialization in 3. can be avoided (see #5639) and probably the serialization in 4. too (also it requires a bit more work).
String allocation might be optimized but this is not what takes the longest running time in my opinion.
Describe the solution you'd like
Instead of serializing the result of the invoked function to a serde_json::Value, it should be serialized directly to a Json String.
Alternatives considered
No response
Additional context
Issue #4026 discusses memory leaks when using the invoke command. My tests also showed memory leaks. These two problems (performance issues and memory leaks) are related.
The text was updated successfully, but these errors were encountered:
Describe the problem
I analysed the code of tauri because I wanted to improve the performances of the
invoke
function (on my project, it takes 30s to read 500Mb of data with a call toinvoke
while simply reading and writing it in JSON takes only 5s).From what I understood by reading the code, here is what happen when we call the
invoke
function:serde_json::Value
[tauri/src/command.rs:197]serde_json::Value
is serialized as aserde_json::Value
(see fix double serialize on invoke #5639) [tauri/src/hooks.rs:196]serde_json::Value
is serialized as a Json String [tauri/src/api/ipc.rs:69]RawValue
, potentially copying all the String in memory [tauri/src/api/ipc.rs:70]RawValue
is converted to an escaped String [tauri/src/api/ipc.rs:85]I think that three serialization is overkill, the serialization in 3. can be avoided (see #5639) and probably the serialization in 4. too (also it requires a bit more work).
String allocation might be optimized but this is not what takes the longest running time in my opinion.
Describe the solution you'd like
Instead of serializing the result of the invoked function to a
serde_json::Value
, it should be serialized directly to a Json String.Alternatives considered
No response
Additional context
Issue #4026 discusses memory leaks when using the
invoke
command. My tests also showed memory leaks. These two problems (performance issues and memory leaks) are related.The text was updated successfully, but these errors were encountered: