Skip to content

Conversation

@Legend-Master
Copy link
Contributor

@Legend-Master Legend-Master commented Apr 4, 2025

Fix #13133

Also:

  • added a feature that allows passing the callback as the parameter of constructor of Channel so you can use it like this new Channel((message) => console.log(message))
  • only go through the fetch process if the data is large enough for it to be faster

@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Apr 4, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2025

Package Changes Through ebb919b

There are 8 changes which include @tauri-apps/api with minor, tauri with minor, tauri-bundler with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, @tauri-apps/cli with minor, tauri-cli with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.4.1 2.5.0
tauri-utils 2.3.1 2.4.0
tauri-bundler 2.3.1 2.4.0
tauri-runtime 2.5.1 2.6.0
tauri-runtime-wry 2.5.1 2.6.0
tauri-codegen 2.1.1 2.1.2
tauri-macros 2.1.1 2.1.2
tauri-plugin 2.1.1 2.1.2
tauri-build 2.1.1 2.1.2
tauri 2.4.1 2.5.0
@tauri-apps/cli 2.4.1 2.5.0
tauri-cli 2.4.1 2.5.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Legend-Master Legend-Master marked this pull request as ready for review April 5, 2025 04:37
@Legend-Master Legend-Master requested a review from a team as a code owner April 5, 2025 04:37
@Legend-Master
Copy link
Contributor Author

This change will require syncing the version of rust crate tauri and js package @tauri-apps/api, since this is marked as a minor I think we can do this right?

@FabianLars
Copy link
Member

hmm, yeah. we've communicated that minor versions are synced a few times (even if we don't fully follow it) so it should be fine. not the first time in 2.x either 🤷

"window.__TAURI_INTERNALS__.invoke('{FETCH_CHANNEL_DATA_COMMAND}', null, {{ headers: {{ '{CHANNEL_ID_HEADER_NAME}': '{data_id}' }} }}).then((response) => window['_' + {}]({{ message: response, id: {i} }})).catch(console.error)",
callback_id.0
))?;
// Don't go through the fetch process if the payload is small
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally someone who agrees with me on that approach 😂

Copy link
Contributor Author

@Legend-Master Legend-Master Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should significantly reduce the load in places like sending updater's download progress

@lucasfernog lucasfernog added this to the 2.5 milestone Apr 12, 2025
@lucasfernog
Copy link
Member

sample benchmark script:

pub fn spam(channel: Channel<tauri::ipc::InvokeResponseBody>) -> tauri::Result<()> {
  for i in 1..=255 {
    channel.send(tauri::ipc::InvokeResponseBody::Raw(
      std::iter::repeat(i).take(1024).collect(),
    ))?;
  }
  Ok(())
}

(change 1024 to whatever you want to test)

channel = new __TAURI__.core.Channel();
i = 0;
channel.onmessage = (m) => {console.log(m); i++; if (i === 255) { console.timeEnd('spam') } };
console.time('spam');
__TAURI__.core.invoke('spam', { channel });

@lucasfernog lucasfernog merged commit 66e6325 into tauri-apps:dev Apr 12, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this from 📬Proposal to 🔎 In audit in Roadmap Apr 12, 2025
InvokeResponseBody::Raw(bytes) if bytes.len() < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
webview.eval(format!(
"window['_{callback_id}']({{ message: {}, index: {current_index} }})",
serde_json::to_string(&bytes)?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@Legend-Master Legend-Master Apr 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty much the only part not written by me in this PR (ebb919b) 😅, anyways, I'll take a look tomorrow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad, I didn't notice that 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 In audit

Development

Successfully merging this pull request may close these issues.

[bug] Listening to Tauri channel events creates memory leak

4 participants