feat(core): Manager::emit_filter and optimize serialization#7512
feat(core): Manager::emit_filter and optimize serialization#7512lucasfernog merged 4 commits intotauri-apps:1.xfrom
Conversation
| .windows_lock() | ||
| .values() | ||
| .filter(|&w| filter(w)) | ||
| .try_for_each(|window| window.emit_internal(event, source_window_label, payload.clone())) |
There was a problem hiding this comment.
I don't think this clone was ever needed. Even when we serialized once per window, it's just creating a string, so using &payload would have been better.
| S: Serialize + Clone, | ||
| F: Fn(&Window<R>) -> bool, | ||
| { | ||
| let emit_args = WindowEmitArgs::from(event, source_window_label, payload)?; |
There was a problem hiding this comment.
serialize once, emit many times
183f8a6 to
454624a
Compare
371d99e to
63c50f0
Compare
63c50f0 to
371d99e
Compare
* added Manager::emit_filter * changed serialization so that it only happens once when sending to multiple window
5c4ebe9 to
7c88c3e
Compare
| let emit_args = WindowEmitArgs::from(event, source_window_label, payload)?; | ||
| assert_event_name_is_valid(event); | ||
| self | ||
| .windows_lock() |
There was a problem hiding this comment.
One question I had here was whether it made more sense to call windows() instead of windows_lock(). This would have the effect of cloning all the windows (bad) but also of not holding the lock open (good). That seems to matter for two reasons. First, plausibly someone could write a filter that needs the lock, which would immediately cause a painful and unintuitive deadlock. Second, emitting might take a while, and ideally you could do other window things while that was happening.
There was a problem hiding this comment.
When triggering events we usually clone the windows, it's safer. We should change this one.
…ps#7512) Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
* feat(tracing): add IPC tracing * span for deserialization * trace spans for IPC command handlers * fix spans usage * app tracing [skip ci] * window tracing * fix run never resolving all spans * fix draw not entered * change level * feat(core): Manager::emit_filter and optimize serialization (#7512) Co-authored-by: Lucas Nogueira <lucas@tauri.studio> * event spans * lint & fix tests * change eval to run sync * fix instrument * update wry * change separator * Update core/tauri/src/plugin.rs Co-authored-by: Jonas Kruckenberg <118265418+CrabNejonas@users.noreply.github.com> * Update core/tauri/src/window.rs Co-authored-by: Jonas Kruckenberg <118265418+CrabNejonas@users.noreply.github.com> * Update core/tauri/src/window.rs Co-authored-by: Jonas Kruckenberg <118265418+CrabNejonas@users.noreply.github.com> * Update core/tauri/src/window.rs Co-authored-by: Jonas Kruckenberg <118265418+CrabNejonas@users.noreply.github.com> * Update core/tauri/src/window.rs Co-authored-by: Jonas Kruckenberg <118265418+CrabNejonas@users.noreply.github.com> * instrument separators * remove on_event trace * skip all arguments on App::build tracing * ipc spans adjustments * delete change file * improve how request and response are added as values (serialize) * do not run evalScript sync on android :( freezes the app * wry 0.35.2 * add change file --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Jonas Kruckenberg <118265418+CrabNejonas@users.noreply.github.com>
I emit a lot of events to multiple--but specific--windows, and one of the bottlenecks there is serialization. There are two problems:
emit_filterserializes on a per-window basisThis fixes both of those. A couple of design choices:
emit_filterwas the most flexible option, compared to taking a HashSet of window ids or similar. It's easy enough to pass|w| some_window_ids.contains(w.label()).What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Checklist
fix: remove a typo, closes #___, #___)Other information