Skip to content
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

perf: lazy load ui, ya, fs, and ps #1903

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
pull_request:
branches: [main]

env:
SCCACHE_GHA_ENABLED: true
RUSTC_WRAPPER: sccache

jobs:
clippy:
runs-on: ubuntu-latest
Expand All @@ -23,6 +27,9 @@ jobs:
prefix-key: rust
shared-key: ubuntu-latest@debug

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Clippy
run: cargo clippy --all

Expand All @@ -43,6 +50,9 @@ jobs:
prefix-key: rust
shared-key: ubuntu-latest@debug

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Rustfmt
run: cargo +nightly fmt --all -- --check

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
- cron: "0 */6 * * *"
workflow_dispatch:

env:
SCCACHE_GHA_ENABLED: true
RUSTC_WRAPPER: sccache

jobs:
build-unix:
strategy:
Expand Down Expand Up @@ -41,6 +45,9 @@ jobs:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Build
run: ./scripts/build.sh ${{ matrix.target }}

Expand Down Expand Up @@ -71,6 +78,9 @@ jobs:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Build
env:
YAZI_GEN_COMPLETIONS: true
Expand Down Expand Up @@ -119,6 +129,9 @@ jobs:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Build
run: ./scripts/build.sh ${{ matrix.target }}

Expand All @@ -144,6 +157,9 @@ jobs:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Build
uses: snapcore/action-build@v1

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
branches: [main]

env:
SCCACHE_GHA_ENABLED: true
RUSTC_WRAPPER: sccache
CARGO_TERM_COLOR: always

jobs:
Expand All @@ -27,6 +29,9 @@ jobs:
prefix-key: rust
shared-key: ${{ matrix.os }}@debug

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Build
run: cargo build --verbose

Expand Down
54 changes: 40 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion yazi-dds/src/body/bye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl BodyBye {
pub fn owned() -> Body<'static> { Self.into() }
}

impl<'a> From<BodyBye> for Body<'a> {
impl From<BodyBye> for Body<'_> {
fn from(value: BodyBye) -> Self { Self::Bye(value) }
}

Expand Down
2 changes: 1 addition & 1 deletion yazi-dds/src/body/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl BodyTab {
pub fn owned(idx: usize) -> Body<'static> { Self { idx }.into() }
}

impl<'a> From<BodyTab> for Body<'a> {
impl From<BodyTab> for Body<'_> {
fn from(value: BodyTab) -> Self { Self::Tab(value) }
}

Expand Down
23 changes: 11 additions & 12 deletions yazi-fm/src/app/commands/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crossterm::event::{MouseEvent, MouseEventKind};
use mlua::{ObjectLike, Table};
use tracing::error;
use yazi_config::MANAGER;
use yazi_plugin::{LUA, bindings::Cast};
use yazi_plugin::LUA;

use crate::{app::App, lives::Lives};

Expand All @@ -17,30 +17,29 @@ impl From<MouseEvent> for Opt {
impl App {
#[yazi_codegen::command]
pub fn mouse(&mut self, opt: Opt) {
let event = opt.event;
let event = yazi_plugin::bindings::MouseEvent::from(opt.event);
let Some(size) = self.term.as_ref().and_then(|t| t.size().ok()) else { return };
let Ok(evt) = yazi_plugin::bindings::MouseEvent::cast(&LUA, event) else { return };

let res = Lives::scope(&self.cx, move || {
let area = yazi_plugin::elements::Rect::from(size);
let root = LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)?;

if matches!(event.kind, MouseEventKind::Down(_) if MANAGER.mouse_events.draggable()) {
root.raw_set("_drag_start", evt.clone())?;
root.raw_set("_drag_start", event)?;
}

match event.kind {
MouseEventKind::Down(_) => root.call_method("click", (evt, false))?,
MouseEventKind::Up(_) => root.call_method("click", (evt, true))?,
MouseEventKind::Down(_) => root.call_method("click", (event, false))?,
MouseEventKind::Up(_) => root.call_method("click", (event, true))?,

MouseEventKind::ScrollDown => root.call_method("scroll", (evt, 1))?,
MouseEventKind::ScrollUp => root.call_method("scroll", (evt, -1))?,
MouseEventKind::ScrollDown => root.call_method("scroll", (event, 1))?,
MouseEventKind::ScrollUp => root.call_method("scroll", (event, -1))?,

MouseEventKind::ScrollRight => root.call_method("touch", (evt, 1))?,
MouseEventKind::ScrollLeft => root.call_method("touch", (evt, -1))?,
MouseEventKind::ScrollRight => root.call_method("touch", (event, 1))?,
MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?,

MouseEventKind::Moved => root.call_method("move", evt)?,
MouseEventKind::Drag(_) => root.call_method("drag", evt)?,
MouseEventKind::Moved => root.call_method("move", event)?,
MouseEventKind::Drag(_) => root.call_method("drag", event)?,
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions yazi-fm/src/app/commands/reflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ impl App {
};

let id: mlua::String = t.get("_id")?;
match id.to_str()?.as_ref() {
"current" => layout.current = *t.raw_get::<yazi_plugin::elements::Rect>("_area")?,
"preview" => layout.preview = *t.raw_get::<yazi_plugin::elements::Rect>("_area")?,
"progress" => layout.progress = *t.raw_get::<yazi_plugin::elements::Rect>("_area")?,
match id.as_bytes().as_ref() {
b"current" => layout.current = *t.raw_get::<yazi_plugin::elements::Rect>("_area")?,
b"preview" => layout.preview = *t.raw_get::<yazi_plugin::elements::Rect>("_area")?,
b"progress" => layout.progress = *t.raw_get::<yazi_plugin::elements::Rect>("_area")?,
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/completion/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<'a> Completion<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
}

impl<'a> Widget for Completion<'a> {
impl Widget for Completion<'_> {
fn render(self, rect: Rect, buf: &mut Buffer) {
let items: Vec<_> = self
.cx
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/confirm/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<'a> Confirm<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
}

impl<'a> Widget for Confirm<'a> {
impl Widget for Confirm<'_> {
fn render(self, _win: Rect, buf: &mut Buffer) {
let confirm = &self.cx.confirm;
let area = self.cx.manager.area(confirm.position);
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/confirm/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<'a> Content<'a> {
pub(crate) fn new(p: Paragraph<'a>) -> Self { Self { p } }
}

impl<'a> Widget for Content<'a> {
impl Widget for Content<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
// Content area
let inner = area.inner(Margin::new(1, 0));
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/confirm/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<'a> List<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
}

impl<'a> Widget for List<'a> {
impl Widget for List<'_> {
fn render(self, mut area: Rect, buf: &mut Buffer) {
// List content area
let inner = area.inner(Margin::new(2, 0));
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/help/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'a> Help<'a> {
}
}

impl<'a> Widget for Help<'a> {
impl Widget for Help<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let help = &self.cx.help;
yazi_plugin::elements::Clear::default().render(area, buf);
Expand Down
4 changes: 2 additions & 2 deletions yazi-fm/src/input/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> Input<'a> {
bail!("Highlighting is disabled");
}

let (theme, syntaxes) = futures::executor::block_on(Highlighter::init());
let (theme, syntaxes) = Highlighter::init();
if let Some(syntax) = syntaxes.find_syntax_by_name("Bourne Again Shell (bash)") {
let mut h = HighlightLines::new(syntax, theme);
let regions = h.highlight_line(self.cx.input.value(), syntaxes)?;
Expand All @@ -31,7 +31,7 @@ impl<'a> Input<'a> {
}
}

impl<'a> Widget for Input<'a> {
impl Widget for Input<'_> {
fn render(self, win: Rect, buf: &mut Buffer) {
let input = &self.cx.input;
let area = self.cx.manager.area(input.position);
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/notify/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> Notify<'a> {
}
}

impl<'a> Widget for Notify<'a> {
impl Widget for Notify<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let notify = &self.cx.notify;

Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/pick/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<'a> Pick<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
}

impl<'a> Widget for Pick<'a> {
impl Widget for Pick<'_> {
fn render(self, _: Rect, buf: &mut Buffer) {
let pick = &self.cx.pick;
let area = self.cx.manager.area(pick.position);
Expand Down
Loading
Loading