Skip to content

Commit

Permalink
perf: using usize instead of *const OsStr reduces memory usage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 26, 2024
1 parent 96bcd82 commit 9ddaba4
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 87 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ubuntu-latest@debug

- name: Clippy
run: cargo clippy --all
Expand All @@ -36,6 +39,9 @@ jobs:
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ubuntu-latest@debug

- name: Rustfmt
run: cargo +nightly fmt --all -- --check
Expand Down
33 changes: 28 additions & 5 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

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

Expand All @@ -54,10 +60,15 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Rust toolchain
run: rustup toolchain install stable --profile minimal
run: |
rustup toolchain install stable --profile minimal
rustup target add ${{ matrix.target }}
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Build
env:
Expand Down Expand Up @@ -98,6 +109,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

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

Expand All @@ -117,10 +134,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build snap
uses: snapcore/action-build@v1
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

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

- name: Rename snap
run: mv yazi_*.snap yazi-${{ matrix.target }}.snap

- name: Upload artifact
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.os }}@debug

- name: Build
run: cargo build --verbose
Expand Down
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,40 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265

## Image Preview

| Platform | Protocol | Support |
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [kitty](https://github.com/kovidgoyal/kitty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
| [Konsole](https://invent.kde.org/utilities/konsole) | [Kitty old protocol](https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kgp_old.rs) | ✅ Built-in |
| [iTerm2](https://iterm2.com) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [WezTerm](https://github.com/wez/wezterm) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Mintty](https://github.com/mintty/mintty) (Git Bash) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [Ghostty](https://mitchellh.com/ghostty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
| [Windows Terminal](https://github.com/microsoft/terminal) (>= v1.22.2702.0) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [Black Box](https://gitlab.gnome.org/raggesilver/blackbox) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [VSCode](https://github.com/microsoft/vscode) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Hyper](https://github.com/vercel/hyper) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Rio](https://github.com/raphamorim/rio) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ❌ Rio doesn't correctly clear images (#1786) |
| X11 / Wayland | Window system protocol | ☑️ [Überzug++](https://github.com/jstkdng/ueberzugpp) required |
| Fallback | [ASCII art (Unicode block)](https://en.wikipedia.org/wiki/ASCII_art) | ☑️ [Chafa](https://hpjansson.org/chafa/) required |
| Platform | Protocol | Support |
| --------------------------------------------------------------------------- | -------------------------------------- | --------------------------------------------- |
| [kitty](https://github.com/kovidgoyal/kitty) | [Kitty unicode placeholders][kgp] | ✅ Built-in |
| [iTerm2](https://iterm2.com) | [Inline images protocol][iip] | ✅ Built-in |
| [WezTerm](https://github.com/wez/wezterm) | [Inline images protocol][iip] | ✅ Built-in |
| [Konsole](https://invent.kde.org/utilities/konsole) | [Kitty old protocol][kgp-old] | ✅ Built-in |
| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format][sixel] | ✅ Built-in |
| [Ghostty](https://mitchellh.com/ghostty) | [Kitty unicode placeholders][kgp] | ✅ Built-in |
| [Windows Terminal](https://github.com/microsoft/terminal) (>= v1.22.2702.0) | [Sixel graphics format][sixel] | ✅ Built-in |
| [st with Sixel patch](https://github.com/bakkeby/st-flexipatch) | [Sixel graphics format][sixel] | ✅ Built-in |
| [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol][iip] | ✅ Built-in |
| [VSCode](https://github.com/microsoft/vscode) | [Inline images protocol][iip] | ✅ Built-in |
| [Rio](https://github.com/raphamorim/rio) | [Inline images protocol][iip] | ❌ Rio doesn't correctly clear images (#1786) |
| [Mintty](https://github.com/mintty/mintty) (Git Bash) | [Inline images protocol][iip] | ✅ Built-in |
| [Black Box](https://gitlab.gnome.org/raggesilver/blackbox) | [Sixel graphics format][sixel] | ✅ Built-in |
| [Hyper](https://github.com/vercel/hyper) | [Inline images protocol][iip] | ✅ Built-in |
| X11 / Wayland | Window system protocol | ☑️ [Überzug++][ueberzug] required |
| Fallback | [ASCII art (Unicode block)][ascii-art] | ☑️ [Chafa][chafa] required |

See https://yazi-rs.github.io/docs/image-preview for details.

<!-- Protocols -->

[kgp]: https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders
[kgp-old]: https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kgp_old.rs
[iip]: https://iterm2.com/documentation-images.html
[sixel]: https://www.vt100.net/docs/vt3xx-gp/chapter14.html
[ascii-art]: https://en.wikipedia.org/wiki/ASCII_art

<!-- Dependencies -->

[ueberzug]: https://github.com/jstkdng/ueberzugpp
[chafa]: https://hpjansson.org/chafa/

## License

Yazi is MIT-licensed. For more information check the [LICENSE](LICENSE) file.
6 changes: 3 additions & 3 deletions yazi-plugin/src/cha/cha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Cha {
reg.add_method("perm", |_, _me, ()| {
Ok(
#[cfg(unix)]
Some(yazi_shared::fs::permissions(_me.perm, _me.is_dummy())),
Some(yazi_shared::fs::permissions(_me.mode, _me.is_dummy())),
#[cfg(windows)]
None::<String>,
)
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Cha {
warn_deprecated(lua.named_registry_value::<RtRef>("rt")?.current());
Ok(
#[cfg(unix)]
Some(yazi_shared::fs::permissions(_me.perm, _me.is_dummy())),
Some(yazi_shared::fs::permissions(_me.mode, _me.is_dummy())),
#[cfg(windows)]
None::<String>,
)
Expand Down Expand Up @@ -131,7 +131,7 @@ impl Cha {
ctime: parse_time(t.raw_get("ctime").ok())?,
mtime: parse_time(t.raw_get("mtime").ok())?,
#[cfg(unix)]
perm: t.raw_get("permissions").unwrap_or_default(),
mode: t.raw_get("mode").unwrap_or_default(),
#[cfg(unix)]
uid: t.raw_get("uid").unwrap_or_default(),
#[cfg(unix)]
Expand Down
22 changes: 11 additions & 11 deletions yazi-shared/src/fs/cha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Cha {
pub ctime: Option<SystemTime>,
pub mtime: Option<SystemTime>,
#[cfg(unix)]
pub perm: libc::mode_t,
pub mode: libc::mode_t,
#[cfg(unix)]
pub uid: libc::uid_t,
#[cfg(unix)]
Expand Down Expand Up @@ -57,7 +57,7 @@ impl From<Metadata> for Cha {
mtime: m.modified().ok(),

#[cfg(unix)]
perm: {
mode: {
use std::os::unix::prelude::PermissionsExt;
m.permissions().mode() as _
},
Expand Down Expand Up @@ -85,7 +85,7 @@ impl From<FileType> for Cha {
let mut kind = ChaKind::DUMMY;

#[cfg(unix)]
let perm = {
let mode = {
use std::os::unix::fs::FileTypeExt;
if t.is_dir() {
kind |= ChaKind::DIR;
Expand Down Expand Up @@ -118,7 +118,7 @@ impl From<FileType> for Cha {
Self {
kind,
#[cfg(unix)]
perm,
mode,
..Default::default()
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Cha {
&& unix_either!(self.ctime == c.ctime, true)
&& self.btime == c.btime
&& self.kind == c.kind
&& unix_either!(self.perm == c.perm, true)
&& unix_either!(self.mode == c.mode, true)
}
}

Expand All @@ -195,27 +195,27 @@ impl Cha {

#[inline]
pub const fn is_block(&self) -> bool {
unix_either!(self.perm & libc::S_IFMT == libc::S_IFBLK, false)
unix_either!(self.mode & libc::S_IFMT == libc::S_IFBLK, false)
}

#[inline]
pub const fn is_char(&self) -> bool {
unix_either!(self.perm & libc::S_IFMT == libc::S_IFCHR, false)
unix_either!(self.mode & libc::S_IFMT == libc::S_IFCHR, false)
}

#[inline]
pub const fn is_fifo(&self) -> bool {
unix_either!(self.perm & libc::S_IFMT == libc::S_IFIFO, false)
unix_either!(self.mode & libc::S_IFMT == libc::S_IFIFO, false)
}

#[inline]
pub const fn is_sock(&self) -> bool {
unix_either!(self.perm & libc::S_IFMT == libc::S_IFSOCK, false)
unix_either!(self.mode & libc::S_IFMT == libc::S_IFSOCK, false)
}

#[inline]
pub const fn is_exec(&self) -> bool { unix_either!(self.perm & libc::S_IXUSR != 0, false) }
pub const fn is_exec(&self) -> bool { unix_either!(self.mode & libc::S_IXUSR != 0, false) }

#[inline]
pub const fn is_sticky(&self) -> bool { unix_either!(self.perm & libc::S_ISVTX != 0, false) }
pub const fn is_sticky(&self) -> bool { unix_either!(self.mode & libc::S_ISVTX != 0, false) }
}
4 changes: 2 additions & 2 deletions yazi-shared/src/fs/fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ async fn _copy_with_progress(from: PathBuf, to: PathBuf, cha: Cha) -> io::Result
tokio::task::spawn_blocking(move || {
let mut reader = std::fs::File::open(from)?;
let mut writer = std::fs::OpenOptions::new()
.mode(cha.perm as u32)
.mode(cha.mode as u32)
.write(true)
.create(true)
.truncate(true)
.open(to)?;

let written = std::io::copy(&mut reader, &mut writer)?;
unsafe { libc::fchmod(writer.as_raw_fd(), cha.perm) };
unsafe { libc::fchmod(writer.as_raw_fd(), cha.mode) };
writer.set_times(ft).ok();

Ok(written)
Expand Down
Loading

0 comments on commit 9ddaba4

Please sign in to comment.