perf(linux): cut OpenGL RSS via isolated auth/Vulkan helpers, malloc_trim, 1024 atlas (v0.1.3)
This commit is contained in:
parent
19ceef9f74
commit
0b2561503f
9 changed files with 175 additions and 23 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -6325,7 +6325,7 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
|
|||
|
||||
[[package]]
|
||||
name = "yandex-music-rs"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"anyhow",
|
||||
|
|
|
|||
20
Cargo.toml
20
Cargo.toml
|
|
@ -1,9 +1,22 @@
|
|||
[package]
|
||||
name = "yandex-music-rs"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2021"
|
||||
description = "Native high-performance, ultra-low-RAM Yandex Music desktop client in Rust + ash Vulkan SDF + taffy + cosmic-text"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
linux-webview = ["dep:wry", "dep:gtk"]
|
||||
|
||||
[[bin]]
|
||||
name = "yandex-music-rs"
|
||||
path = "src/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "yandex-music-auth"
|
||||
path = "src/bin/yandex_music_auth.rs"
|
||||
required-features = ["linux-webview"]
|
||||
|
||||
[dependencies]
|
||||
# Core Windowing & Native UI Engine (ash SDF + taffy + cosmic-text)
|
||||
winit = "0.30"
|
||||
|
|
@ -68,8 +81,8 @@ windows-sys = { version = "0.59", features = [
|
|||
] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
wry = { version = "0.51", default-features = false, features = ["os-webview"] }
|
||||
gtk = "0.18"
|
||||
wry = { version = "0.51", default-features = false, features = ["os-webview"], optional = true }
|
||||
gtk = { version = "0.18", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
naga = { version = "24", features = ["wgsl-in", "spv-out"] }
|
||||
|
|
@ -94,6 +107,7 @@ recommends = "libvulkan1, mesa-vulkan-drivers, libgl1, libegl1"
|
|||
maintainer-scripts = "packaging/debian"
|
||||
assets = [
|
||||
["target/release/yandex-music-rs", "usr/bin/", "755"],
|
||||
["target/release/yandex-music-auth", "usr/bin/", "755"],
|
||||
["assets/icons/app_icon.png", "usr/share/pixmaps/yandex-music-rs.png", "644"],
|
||||
["assets/icons/app_48.png", "usr/share/icons/hicolor/48x48/apps/yandex-music-rs.png", "644"],
|
||||
["packaging/icons/64x64.png", "usr/share/icons/hicolor/64x64/apps/yandex-music-rs.png", "644"],
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
Готовые сборки доступны на странице [Releases](https://git.tatar/marwy/yandex-music-rs/releases):
|
||||
|
||||
- **Windows (x64)**: скачайте `yandex-music-rs-v0.1.2-windows-x86_64.exe` и запустите (переносной файл, установка не требуется).
|
||||
- **Linux (Debian / Ubuntu x64)**: скачайте `yandex-music-rs_0.1.2-1_amd64.deb` и установите:
|
||||
- **Windows (x64)**: скачайте `yandex-music-rs-v0.1.3-windows-x86_64.exe` и запустите (переносной файл, установка не требуется).
|
||||
- **Linux (Debian / Ubuntu x64)**: скачайте `yandex-music-rs_0.1.3-1_amd64.deb` и установите:
|
||||
```bash
|
||||
sudo apt install ./yandex-music-rs_0.1.2-1_amd64.deb
|
||||
sudo apt install ./yandex-music-rs_0.1.3-1_amd64.deb
|
||||
```
|
||||
- **Linux (generic x64)**: архив `yandex-music-rs-v0.1.2-linux-x86_64.tar.gz` с готовым бинарником.
|
||||
- **Linux (generic x64)**: архив `yandex-music-rs-v0.1.3-linux-x86_64.tar.gz` с готовыми бинарниками (`yandex-music-rs` + `yandex-music-auth`).
|
||||
|
||||
## Стек и возможности
|
||||
|
||||
|
|
|
|||
|
|
@ -13,5 +13,10 @@ else
|
|||
fi
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
cargo deb --output "$PROJECT_DIR/target/debian/"
|
||||
# 1. Main player binary: zero WebKit2GTK / GTK DT_NEEDED entries
|
||||
cargo build --release --bin yandex-music-rs
|
||||
# 2. Isolated Linux OAuth WebView helper binary
|
||||
cargo build --release --features linux-webview --bin yandex-music-auth
|
||||
# 3. Package both binaries into .deb (cargo-deb resolves target/release/* via CARGO_TARGET_DIR)
|
||||
cargo deb --no-build --output "$PROJECT_DIR/target/debian/"
|
||||
ls -lh "$PROJECT_DIR/target/debian/"*.deb
|
||||
|
|
|
|||
3
src/bin/yandex_music_auth.rs
Normal file
3
src/bin/yandex_music_auth.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
yandex_music_rs::native::run_auth_webview_subprocess();
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ use crate::engine::types::{
|
|||
Color, DisplayList, Pos2, Rect, Vec2, GLYPH_ATLAS_TEXTURE_ID,
|
||||
};
|
||||
|
||||
const ATLAS_SIZE: u32 = 2048;
|
||||
const ATLAS_SIZE: u32 = 1024;
|
||||
|
||||
/// The 4 official Yandex Music 5.129.0 font roles loaded from `assets/fonts/`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
|
|
|||
38
src/main.rs
38
src/main.rs
|
|
@ -169,6 +169,32 @@ fn init_opengl_backend(
|
|||
Ok((window, RenderBackend::OpenGl(gl)))
|
||||
}
|
||||
|
||||
/// Probe hardware Vulkan in an isolated short-lived subprocess on Linux so Mesa's software
|
||||
/// `libvulkan_lvp.so` + `libLLVM.so` (~80–100 MB) are NEVER mapped into the main OpenGL player
|
||||
/// process on legacy GPUs without hardware Vulkan (e.g. Intel HD Graphics 3000).
|
||||
fn has_hardware_vulkan_isolated() -> bool {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use std::process::{Command, Stdio};
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Ok(status) = Command::new(exe)
|
||||
.arg("--probe-vulkan")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
{
|
||||
return status.success();
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
VulkanContext::has_hardware_vulkan()
|
||||
}
|
||||
}
|
||||
|
||||
struct AppRunner {
|
||||
runtime: tokio::runtime::Runtime,
|
||||
// Drop GPU backend BEFORE the native winit Window so Vulkan/GL surfaces destroy cleanly!
|
||||
|
|
@ -413,7 +439,12 @@ impl AppRunner {
|
|||
let is_max = window.is_maximized();
|
||||
let elapsed = shell.elapsed_secs();
|
||||
|
||||
let had_splash = shell.splash.is_some();
|
||||
let (frame, win_cmd) = shell.render_frame(logical, sf, elapsed, is_max);
|
||||
if had_splash && shell.splash.is_none() {
|
||||
telemetry::PerfTelemetry::trim_working_set();
|
||||
shell.app.perf.sample_memory();
|
||||
}
|
||||
|
||||
// Sync cursor icon
|
||||
if frame.cursor != self.last_cursor {
|
||||
|
|
@ -561,7 +592,7 @@ impl ApplicationHandler for AppRunner {
|
|||
RendererPreference::Vulkan => init_vulkan_backend(event_loop, init_w, init_h)
|
||||
.expect("Failed to initialize Vulkan renderer (--renderer=vulkan)"),
|
||||
RendererPreference::Auto => {
|
||||
if VulkanContext::has_hardware_vulkan() {
|
||||
if has_hardware_vulkan_isolated() {
|
||||
match init_vulkan_backend(event_loop, init_w, init_h) {
|
||||
Ok(pair) => pair,
|
||||
Err(vk_err) => {
|
||||
|
|
@ -1028,6 +1059,11 @@ fn acquire_single_instance_lock() -> bool {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
// Isolated Vulkan HW probe subprocess (keeps libvulkan_lvp / libLLVM out of main Linux RSS)
|
||||
if std::env::args().any(|a| a == "--probe-vulkan") {
|
||||
std::process::exit(if VulkanContext::has_hardware_vulkan() { 0 } else { 1 });
|
||||
}
|
||||
|
||||
// Isolated zero-resident-RAM WebView2 OAuth subprocess (exits immediately after login!)
|
||||
if std::env::args().any(|a| a == "--auth-webview") {
|
||||
run_auth_webview_subprocess();
|
||||
|
|
|
|||
|
|
@ -451,13 +451,9 @@ mod imp {
|
|||
mod imp {
|
||||
use super::NativeEvent;
|
||||
use crate::api::models::Track;
|
||||
use crate::api::signing::extract_oauth_token;
|
||||
use crate::api::YANDEX_OAUTH_URL;
|
||||
use gtk::prelude::*;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::{Command, Stdio};
|
||||
use winit::window::Window;
|
||||
use wry::{WebViewBuilder, WebViewBuilderExtUnix};
|
||||
|
||||
const OAUTH_TOKEN_PREFIX: &str = "YM_OAUTH_TOKEN:";
|
||||
|
||||
|
|
@ -480,8 +476,17 @@ mod imp {
|
|||
winit::window::Icon::from_rgba(img.into_raw(), w, h).ok()
|
||||
}
|
||||
|
||||
/// Entry point for the short-lived `--auth-webview` subprocess on Linux (GTK3 + WebKitGTK).
|
||||
/// Entry point for the short-lived `yandex-music-auth` subprocess on Linux (GTK3 + WebKitGTK).
|
||||
/// Compiled ONLY when `--features linux-webview` is enabled so the main player binary has
|
||||
/// zero `libwebkit2gtk` / `libjavascriptcoregtk` / `libgtk-3` DT_NEEDED dependencies!
|
||||
#[cfg(feature = "linux-webview")]
|
||||
pub fn run_auth_webview_subprocess() {
|
||||
use crate::api::signing::extract_oauth_token;
|
||||
use crate::api::YANDEX_OAUTH_URL;
|
||||
use gtk::prelude::*;
|
||||
use std::io::Write;
|
||||
use wry::{WebViewBuilder, WebViewBuilderExtUnix};
|
||||
|
||||
// Avoid blank WebKitGTK window on NVIDIA/Wayland/VM drivers during OAuth login.
|
||||
if std::env::var_os("WEBKIT_DISABLE_DMABUF_RENDERER").is_none() {
|
||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||
|
|
@ -554,14 +559,38 @@ mod imp {
|
|||
gtk::main();
|
||||
}
|
||||
|
||||
/// Spawn the isolated `--auth-webview` subprocess and return the captured OAuth token.
|
||||
#[cfg(not(feature = "linux-webview"))]
|
||||
pub fn run_auth_webview_subprocess() {
|
||||
eprintln!("yandex-music-auth helper required");
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
/// Spawn the isolated `yandex-music-auth` helper binary (or `--auth-webview` if built with
|
||||
/// `linux-webview`) and return the captured OAuth token.
|
||||
pub fn spawn_auth_webview_subprocess() -> anyhow::Result<String> {
|
||||
let exe = std::env::current_exe()?;
|
||||
let mut child = Command::new(exe)
|
||||
let sibling_helper = exe.with_file_name("yandex-music-auth");
|
||||
|
||||
let mut child = if sibling_helper.is_file() {
|
||||
Command::new(&sibling_helper)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()?
|
||||
} else if let Ok(c) = Command::new("yandex-music-auth")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
c
|
||||
} else if cfg!(feature = "linux-webview") {
|
||||
Command::new(&exe)
|
||||
.arg("--auth-webview")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()?;
|
||||
.spawn()?
|
||||
} else {
|
||||
anyhow::bail!("WebKitGTK auth helper (yandex-music-auth) unavailable");
|
||||
};
|
||||
|
||||
let stdout = child
|
||||
.stdout
|
||||
|
|
|
|||
|
|
@ -61,7 +61,17 @@ impl PerfTelemetry {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[cfg(all(target_os = "linux", target_env = "gnu"))]
|
||||
pub fn trim_working_set() {
|
||||
extern "C" {
|
||||
fn malloc_trim(pad: usize) -> i32;
|
||||
}
|
||||
unsafe {
|
||||
let _ = malloc_trim(0);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(windows, all(target_os = "linux", target_env = "gnu"))))]
|
||||
pub fn trim_working_set() {}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
|
@ -86,7 +96,62 @@ impl PerfTelemetry {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn sample_memory(&mut self) {
|
||||
fn parse_kb_line(line: &str, prefix: &str) -> Option<u64> {
|
||||
let rest = line.strip_prefix(prefix)?;
|
||||
rest.split_whitespace().next()?.parse::<u64>().ok()
|
||||
}
|
||||
|
||||
if let Ok(rollup) = std::fs::read_to_string("/proc/self/smaps_rollup") {
|
||||
let mut rss_kb: Option<u64> = None;
|
||||
let mut pss_kb: Option<u64> = None;
|
||||
let mut priv_clean_kb: u64 = 0;
|
||||
let mut priv_dirty_kb: u64 = 0;
|
||||
let mut has_priv = false;
|
||||
for line in rollup.lines() {
|
||||
if let Some(v) = parse_kb_line(line, "Rss:") {
|
||||
rss_kb = Some(v);
|
||||
} else if let Some(v) = parse_kb_line(line, "Pss:") {
|
||||
pss_kb = Some(v);
|
||||
} else if let Some(v) = parse_kb_line(line, "Private_Clean:") {
|
||||
priv_clean_kb = v;
|
||||
has_priv = true;
|
||||
} else if let Some(v) = parse_kb_line(line, "Private_Dirty:") {
|
||||
priv_dirty_kb = v;
|
||||
has_priv = true;
|
||||
}
|
||||
}
|
||||
if let Some(rss) = rss_kb {
|
||||
self.working_set_mb = rss as f32 / 1024.0;
|
||||
let priv_kb = if has_priv {
|
||||
priv_clean_kb.saturating_add(priv_dirty_kb)
|
||||
} else {
|
||||
pss_kb.unwrap_or(rss)
|
||||
};
|
||||
self.private_mb = priv_kb as f32 / 1024.0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(status) = std::fs::read_to_string("/proc/self/status") {
|
||||
let mut rss_kb: Option<u64> = None;
|
||||
let mut anon_kb: Option<u64> = None;
|
||||
for line in status.lines() {
|
||||
if let Some(v) = parse_kb_line(line, "VmRSS:") {
|
||||
rss_kb = Some(v);
|
||||
} else if let Some(v) = parse_kb_line(line, "RssAnon:") {
|
||||
anon_kb = Some(v);
|
||||
}
|
||||
}
|
||||
if let Some(rss) = rss_kb {
|
||||
self.working_set_mb = rss as f32 / 1024.0;
|
||||
self.private_mb = anon_kb.unwrap_or(rss) as f32 / 1024.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(windows, target_os = "linux")))]
|
||||
pub fn sample_memory(&mut self) {
|
||||
self.working_set_mb = 28.0;
|
||||
self.private_mb = 22.0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue