From ea7fa2127cc032b669a4825157ace244f06cf31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Sat, 6 Jun 2026 14:35:12 +0800 Subject: [PATCH] perf: eliminate hacks in image and UI conflict resolution (#4022) --- CHANGELOG.md | 5 +++++ yazi-binding/src/data/any.rs | 16 ---------------- yazi-binding/src/data/mod.rs | 1 - yazi-binding/src/lib.rs | 2 +- yazi-fm/src/app/render.rs | 30 +++--------------------------- yazi-tui/src/raterm.rs | 4 +--- yazi-widgets/src/clear.rs | 4 ++-- 7 files changed, 12 insertions(+), 50 deletions(-) delete mode 100644 yazi-binding/src/data/any.rs delete mode 100644 yazi-binding/src/data/mod.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8db42d..ea999c49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): - Deprecate `backward --far` and `forward --far` in favor of `backward wide` and `forward wide`, respectively ([#4012]) +### Improved + +- Eliminate hacks in image and UI conflict resolution ([#4022]) + ## [v26.5.6] ### Added @@ -1737,3 +1741,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#3990]: https://github.com/sxyazi/yazi/pull/3990 [#4005]: https://github.com/sxyazi/yazi/pull/4005 [#4012]: https://github.com/sxyazi/yazi/pull/4012 +[#4022]: https://github.com/sxyazi/yazi/pull/4022 diff --git a/yazi-binding/src/data/any.rs b/yazi-binding/src/data/any.rs deleted file mode 100644 index eb5e353d..00000000 --- a/yazi-binding/src/data/any.rs +++ /dev/null @@ -1,16 +0,0 @@ -use mlua::UserData; -use yazi_codegen::FromLuaOwned; - -#[derive(FromLuaOwned)] -pub struct DataAny(Box); - -impl DataAny { - pub fn new(value: T) -> Self - where - T: yazi_shared::data::DataAny, - { - Self(Box::new(value)) - } -} - -impl UserData for DataAny {} diff --git a/yazi-binding/src/data/mod.rs b/yazi-binding/src/data/mod.rs deleted file mode 100644 index 83b99df1..00000000 --- a/yazi-binding/src/data/mod.rs +++ /dev/null @@ -1 +0,0 @@ -yazi_macro::mod_flat!(any); diff --git a/yazi-binding/src/lib.rs b/yazi-binding/src/lib.rs index b6f1f48b..4efa34b6 100644 --- a/yazi-binding/src/lib.rs +++ b/yazi-binding/src/lib.rs @@ -1,5 +1,5 @@ mod macros; -yazi_macro::mod_pub!(config data elements event keymap process theme); +yazi_macro::mod_pub!(config elements event keymap process theme); yazi_macro::mod_flat!(access calculator cha chan composer dnd error fd file handle icon id image input iter layer mouse path permit range runtime scheme selector stage style tty url utils); diff --git a/yazi-fm/src/app/render.rs b/yazi-fm/src/app/render.rs index 245c4c21..175abe46 100644 --- a/yazi-fm/src/app/render.rs +++ b/yazi-fm/src/app/render.rs @@ -1,7 +1,7 @@ use std::{io::Write, sync::atomic::{AtomicU8, Ordering}, time::Instant}; use anyhow::Result; -use ratatui::{CompletedFrame, backend::Backend, buffer::Buffer, layout::Position}; +use ratatui::layout::Position; use yazi_actor::{Ctx, lives::Lives}; use yazi_binding::runtime_scope; use yazi_config::LAYOUT; @@ -10,7 +10,6 @@ use yazi_plugin::LUA; use yazi_shared::{data::Data, event::NEED_RENDER}; use yazi_term::{CursorStyle, sequence::{BeginSyncUpdate, EndSyncUpdate, MoveTo, SetCursorStyle, ShowCursor}}; use yazi_tty::TTY; -use yazi_tui::RatermBackend; use yazi_widgets::COLLISION; use crate::{app::App, root::Root}; @@ -30,15 +29,12 @@ impl App { let collision = COLLISION.swap(false, Ordering::Relaxed); let preview_rect = LAYOUT.get().preview; - let frame = term.draw(|f| { + term.draw(|f| { _ = Lives::scope(&self.core, || { runtime_scope!(LUA, "root", Ok(f.render_widget(Root::new(&self.core), f.area()))) }); })?; - if COLLISION.load(Ordering::Relaxed) { - Self::patch(frame); - } if !self.core.notify.messages.is_empty() { self.render_partially()?; } @@ -61,7 +57,7 @@ impl App { Self::routine(true, None); let _guard = scopeguard::guard(self.core.cursor(), |c| Self::routine(false, c)); - let frame = term.draw_partial(|f| { + term.draw_partial(|f| { _ = Lives::scope(&self.core, || { runtime_scope!(LUA, "root", { f.render_widget(crate::tasks::Progress::new(&self.core), f.area()); @@ -71,29 +67,9 @@ impl App { }); })?; - if COLLISION.load(Ordering::Relaxed) { - Self::patch(frame); - } succ!(); } - #[inline] - fn patch(frame: CompletedFrame) { - let mut new = Buffer::empty(frame.area); - for y in new.area.top()..new.area.bottom() { - for x in new.area.left()..new.area.right() { - let cell = &frame.buffer[(x, y)]; - if cell.skip { - new[(x, y)] = cell.clone(); - } - new[(x, y)].set_skip(!cell.skip); - } - } - - let patches = frame.buffer.diff(&new); - RatermBackend::new(&mut *TTY.lockout()).draw(patches.into_iter()).ok(); - } - fn routine(push: bool, cursor: Option<(Position, CursorStyle)>) { static COUNT: AtomicU8 = AtomicU8::new(0); if push && COUNT.fetch_add(1, Ordering::Relaxed) != 0 { diff --git a/yazi-tui/src/raterm.rs b/yazi-tui/src/raterm.rs index 3b528821..4a7a498b 100644 --- a/yazi-tui/src/raterm.rs +++ b/yazi-tui/src/raterm.rs @@ -123,9 +123,7 @@ impl Raterm { let buffer = frame.buffer_mut(); for y in self.last_area.top()..self.last_area.bottom() { for x in self.last_area.left()..self.last_area.right() { - let mut cell = self.last_buffer[(x, y)].clone(); - cell.skip = false; - buffer[(x, y)] = cell; + buffer[(x, y)] = self.last_buffer[(x, y)].clone(); } } diff --git a/yazi-widgets/src/clear.rs b/yazi-widgets/src/clear.rs index 2b615fe5..c7809780 100644 --- a/yazi-widgets/src/clear.rs +++ b/yazi-widgets/src/clear.rs @@ -1,6 +1,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; -use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; +use ratatui::{buffer::{Buffer, CellDiffOption}, layout::Rect, widgets::Widget}; use yazi_adapter::ADAPTOR; pub static COLLISION: AtomicBool = AtomicBool::new(false); @@ -23,7 +23,7 @@ impl Widget for Clear { COLLISION.store(true, Ordering::Relaxed); for y in r.top()..r.bottom() { for x in r.left()..r.right() { - buf[(x, y)].set_skip(true); + buf[(x, y)].set_diff_option(CellDiffOption::AlwaysUpdate); } } }