Skip to content

Commit 9ddaba4

Browse files
committed
perf: using usize instead of *const OsStr reduces memory usage (#1839)
1 parent 96bcd82 commit 9ddaba4

File tree

8 files changed

+121
-87
lines changed

8 files changed

+121
-87
lines changed

.github/workflows/check.yml

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
2020
- name: Setup Rust cache
2121
uses: Swatinem/rust-cache@v2
22+
with:
23+
prefix-key: rust
24+
shared-key: ubuntu-latest@debug
2225

2326
- name: Clippy
2427
run: cargo clippy --all
@@ -36,6 +39,9 @@ jobs:
3639
3740
- name: Setup Rust cache
3841
uses: Swatinem/rust-cache@v2
42+
with:
43+
prefix-key: rust
44+
shared-key: ubuntu-latest@debug
3945

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

.github/workflows/draft.yml

+28-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232
echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV
3333
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc" >> $GITHUB_ENV
3434
35+
- name: Setup Rust cache
36+
uses: Swatinem/rust-cache@v2
37+
with:
38+
prefix-key: rust
39+
shared-key: ${{ matrix.target }}@release
40+
3541
- name: Build
3642
run: ./scripts/build.sh ${{ matrix.target }}
3743

@@ -54,10 +60,15 @@ jobs:
5460
- uses: actions/checkout@v4
5561

5662
- name: Setup Rust toolchain
57-
run: rustup toolchain install stable --profile minimal
63+
run: |
64+
rustup toolchain install stable --profile minimal
65+
rustup target add ${{ matrix.target }}
5866
59-
- name: Add target
60-
run: rustup target add ${{ matrix.target }}
67+
- name: Setup Rust cache
68+
uses: Swatinem/rust-cache@v2
69+
with:
70+
prefix-key: rust
71+
shared-key: ${{ matrix.target }}@release
6172

6273
- name: Build
6374
env:
@@ -98,6 +109,12 @@ jobs:
98109
steps:
99110
- uses: actions/checkout@v4
100111

112+
- name: Setup Rust cache
113+
uses: Swatinem/rust-cache@v2
114+
with:
115+
prefix-key: rust
116+
shared-key: ${{ matrix.target }}@release
117+
101118
- name: Build
102119
run: ./scripts/build.sh ${{ matrix.target }}
103120

@@ -117,10 +134,16 @@ jobs:
117134
steps:
118135
- uses: actions/checkout@v4
119136

120-
- name: Build snap
121-
uses: snapcore/action-build@v1
137+
- name: Setup Rust cache
138+
uses: Swatinem/rust-cache@v2
139+
with:
140+
prefix-key: rust
141+
shared-key: ${{ matrix.target }}@release
122142

123143
- name: Build
144+
uses: snapcore/action-build@v1
145+
146+
- name: Rename snap
124147
run: mv yazi_*.snap yazi-${{ matrix.target }}.snap
125148

126149
- name: Upload artifact

.github/workflows/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323

2424
- name: Setup Rust cache
2525
uses: Swatinem/rust-cache@v2
26+
with:
27+
prefix-key: rust
28+
shared-key: ${{ matrix.os }}@debug
2629

2730
- name: Build
2831
run: cargo build --verbose

README.md

+31-17
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,40 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265
4444

4545
## Image Preview
4646

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

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

68+
<!-- Protocols -->
69+
70+
[kgp]: https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders
71+
[kgp-old]: https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kgp_old.rs
72+
[iip]: https://iterm2.com/documentation-images.html
73+
[sixel]: https://www.vt100.net/docs/vt3xx-gp/chapter14.html
74+
[ascii-art]: https://en.wikipedia.org/wiki/ASCII_art
75+
76+
<!-- Dependencies -->
77+
78+
[ueberzug]: https://github.com/jstkdng/ueberzugpp
79+
[chafa]: https://hpjansson.org/chafa/
80+
6781
## License
6882

6983
Yazi is MIT-licensed. For more information check the [LICENSE](LICENSE) file.

yazi-plugin/src/cha/cha.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Cha {
6767
reg.add_method("perm", |_, _me, ()| {
6868
Ok(
6969
#[cfg(unix)]
70-
Some(yazi_shared::fs::permissions(_me.perm, _me.is_dummy())),
70+
Some(yazi_shared::fs::permissions(_me.mode, _me.is_dummy())),
7171
#[cfg(windows)]
7272
None::<String>,
7373
)
@@ -95,7 +95,7 @@ impl Cha {
9595
warn_deprecated(lua.named_registry_value::<RtRef>("rt")?.current());
9696
Ok(
9797
#[cfg(unix)]
98-
Some(yazi_shared::fs::permissions(_me.perm, _me.is_dummy())),
98+
Some(yazi_shared::fs::permissions(_me.mode, _me.is_dummy())),
9999
#[cfg(windows)]
100100
None::<String>,
101101
)
@@ -131,7 +131,7 @@ impl Cha {
131131
ctime: parse_time(t.raw_get("ctime").ok())?,
132132
mtime: parse_time(t.raw_get("mtime").ok())?,
133133
#[cfg(unix)]
134-
perm: t.raw_get("permissions").unwrap_or_default(),
134+
mode: t.raw_get("mode").unwrap_or_default(),
135135
#[cfg(unix)]
136136
uid: t.raw_get("uid").unwrap_or_default(),
137137
#[cfg(unix)]

yazi-shared/src/fs/cha.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Cha {
2626
pub ctime: Option<SystemTime>,
2727
pub mtime: Option<SystemTime>,
2828
#[cfg(unix)]
29-
pub perm: libc::mode_t,
29+
pub mode: libc::mode_t,
3030
#[cfg(unix)]
3131
pub uid: libc::uid_t,
3232
#[cfg(unix)]
@@ -57,7 +57,7 @@ impl From<Metadata> for Cha {
5757
mtime: m.modified().ok(),
5858

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

8787
#[cfg(unix)]
88-
let perm = {
88+
let mode = {
8989
use std::os::unix::fs::FileTypeExt;
9090
if t.is_dir() {
9191
kind |= ChaKind::DIR;
@@ -118,7 +118,7 @@ impl From<FileType> for Cha {
118118
Self {
119119
kind,
120120
#[cfg(unix)]
121-
perm,
121+
mode,
122122
..Default::default()
123123
}
124124
}
@@ -173,7 +173,7 @@ impl Cha {
173173
&& unix_either!(self.ctime == c.ctime, true)
174174
&& self.btime == c.btime
175175
&& self.kind == c.kind
176-
&& unix_either!(self.perm == c.perm, true)
176+
&& unix_either!(self.mode == c.mode, true)
177177
}
178178
}
179179

@@ -195,27 +195,27 @@ impl Cha {
195195

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

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

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

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

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

219219
#[inline]
220-
pub const fn is_sticky(&self) -> bool { unix_either!(self.perm & libc::S_ISVTX != 0, false) }
220+
pub const fn is_sticky(&self) -> bool { unix_either!(self.mode & libc::S_ISVTX != 0, false) }
221221
}

yazi-shared/src/fs/fns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ async fn _copy_with_progress(from: PathBuf, to: PathBuf, cha: Cha) -> io::Result
258258
tokio::task::spawn_blocking(move || {
259259
let mut reader = std::fs::File::open(from)?;
260260
let mut writer = std::fs::OpenOptions::new()
261-
.mode(cha.perm as u32)
261+
.mode(cha.mode as u32)
262262
.write(true)
263263
.create(true)
264264
.truncate(true)
265265
.open(to)?;
266266

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

271271
Ok(written)

0 commit comments

Comments
 (0)