Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Measure tray-mode memory and cross-build S1 for ARM64
Beebb0c9970dfcb
diff --git a/scripts/qmake-arm64.ps1 b/scripts/qmake-arm64.ps1new file mode 100644index 0000000..7112dfd--- /dev/null+++ b/scripts/qmake-arm64.ps1@@ -0,0 +1,68 @@+# SPDX-License-Identifier: GPL-3.0-or-later+<#+.SYNOPSIS+ Prepares a qmake that cross-compiles for Windows ARM64 from an x64 host+ and prints its path, for use as the QMAKE environment variable.++.DESCRIPTION+ Qt's ARM64 kit ships host-qmake.bat, but cxx-qt runs qmake with an empty+ environment, which a .bat file can't survive. Instead, this copies the x64+ host qmake (and the Qt6Core.dll it needs) into a cache folder next to a+ qt.conf describing the ARM64 kit.+ Headers and libraries then come from the ARM64 kit; moc, rcc and+ qmlcachegen run from the x64 kit.++.EXAMPLE+ $env:QMAKE = ./scripts/qmake-arm64.ps1+ cargo build --release --target aarch64-pc-windows-msvc -p s1-qt-rust+#>+param(+ [string]$QtRoot = "C:\Qt\6.12.0",+ [string]$OutDir = (Join-Path $env:LOCALAPPDATA "Nectarlink\dev\qmake-arm64")+)+$ErrorActionPreference = "Stop"++$hostKit = Join-Path $QtRoot "msvc2022_64"+$targetKit = Join-Path $QtRoot "msvc2022_arm64"+foreach ($kit in $hostKit, $targetKit) {+ if (-not (Test-Path (Join-Path $kit "bin"))) { throw "Qt kit not found: $kit" }+}++New-Item -ItemType Directory -Force $OutDir | Out-Null+# qmake links Qt6Core dynamically and is run with an empty PATH, so its DLL+# must sit next to it.+foreach ($file in "qmake6.exe", "Qt6Core.dll") {+ Copy-Item (Join-Path $hostKit "bin\$file") (Join-Path $OutDir $file) -Force+}++# Same layout as the kit's target_qt.conf, with absolute paths.+$t = $targetKit -replace '\\', '/'+$h = $hostKit -replace '\\', '/'+@"+[Paths]+Prefix=$t+Documentation=doc+Headers=include+Libraries=lib+LibraryExecutables=bin+Binaries=bin+Plugins=plugins+QmlImports=qml+ArchData=.+Data=.+Translations=translations+Examples=examples+Tests=tests+Settings=etc/xdg+HostPrefix=$h+HostBinaries=bin+HostLibraries=lib+HostLibraryExecutables=bin+HostData=$t+Sysroot=+SysrootifyPrefix=false+TargetSpec=win32-arm64-msvc+HostSpec=win32-msvc+"@ | Set-Content -Encoding ascii (Join-Path $OutDir "qt.conf")++Join-Path $OutDir "qmake6.exe"diff --git a/spikes/s1-qt-rust/README.md b/spikes/s1-qt-rust/README.mdindex 8d32452..c60f41f 100644--- a/spikes/s1-qt-rust/README.md+++ b/spikes/s1-qt-rust/README.md@@ -3,21 +3,25 @@Throwaway code. What we keep is the knowledge below.Run (needs Qt 6.12 on PATH and `QMAKE` set):-`cargo run --release -p s1-qt-rust` · `-- --autotest` (self-driving measurement) · `-- --mica` · `-- --video`+`cargo run --release -p s1-qt-rust` · `-- --autotest` (self-driving measurement) · `-- --tray-test`+(open, close, measure tray mode) · `-- --mica` · `-- --video` · `-- --no-window`++ARM64: `$env:QMAKE = ./scripts/qmake-arm64.ps1` then+`cargo build --release --target aarch64-pc-windows-msvc -p s1-qt-rust`## Results (2026-10-05, this machine, 144 Hz display, release build)| Criterion | Budget | Result | ||---|---|---|---|| First frame | < 500 ms | ~400 ms | ✅ |-| RAM, main window open | < 120 MB | ~88 MB idle, ~104 MB under 10k events/s | ✅ |+| RAM, main window open | < 120 MB | ~88 MB working set idle (Task Manager: 32.5 MB private), ~104 MB under 10k events/s | ✅ || Smoothness under load | 120 fps | 144 fps avg, 143 min (display max) at 10,000 core events/s + hero transition | ✅ || Core→UI events | 10k/s without stutter | ✅ with coalescing (see below) | ✅ || Bloom design fidelity | matches mockups | Home, notification cards, Deck, shared-element conversation transition, real blur (MultiEffect) | ✅ || Mica | works | Works on D3D11 with no cost: 144 fps under load, same memory (see lesson 7) | ✅ || Video in scene graph (zero copy) | works | 1080p60 GPU frames from a Rust thread on its own D3D11 device: 240/240 shown, 0 dropped, 144 fps alongside 10k events/s. Video alone: 11% of one core, 9% GPU, +6.5 MB | ✅ |-| ARM64 build | CI builds | ⏳ not tried | follow-up |-| Tray-only RAM < 60 MB | | ⏳ not measured (no tray mode yet) | follow-up |+| ARM64 build | CI builds | Cross-builds from x64 into an ARM64 exe linking ARM64 Qt; not run yet (needs ARM64 hardware or a `windows-11-arm` CI runner) | ✅ build |+| Tray-only RAM | < 60 MB | After closing the main window: 64 MB working set, 52 MB private commit, **19.6 MB in Task Manager**. Never-opened floor: 34 / 23 MB. Core not included yet | ✅ |## Lessons (apply to the real `nectarlink-qt`)@@ -53,12 +57,27 @@ Run (needs Qt 6.12 on PATH and `QMAKE` set):`QSGTexture` wrapper's lifetime shorter than the native texture.11. Wake the item with a coalesced notifier (at most one queued `update()`),the same idea as `UiPump`, so the scene only re-renders on new frames.+12. **Tray mode = no windows**, not hidden windows: `App.qml` creates the+ main window on demand and destroys it on close, freeing its GPU device+ and scene graph (private memory 100 → 52 MB). About 30 MB of the+ remainder is the GPU driver, which stays loaded once used; trimming the+ QML component cache gains nothing. Report memory as Task Manager does+ (private working set) next to working set and private commit, since+ they differ by 3×.+13. **ARM64 cross builds** need a qmake that runs on the host but describes+ the ARM64 kit. Qt's `host-qmake.bat` can't be used because cxx-qt runs+ qmake with an empty environment; `scripts/qmake-arm64.ps1` makes an+ equivalent with a copied x64 qmake, `Qt6Core.dll` and `qt.conf`.## Verdict-**Gate passed for the UI stack** (looks, smoothness, memory, startup, event throughput).-ARM64 and tray-mode memory remain to verify; S2 replaces the test pattern-with the hardware H.264/H.265 decoder (NV12 → RGBA via the D3D11 video-processor, into the same shared texture). The-real app also needs a custom title bar so Mica runs edge to edge (the system-caption is drawn in the accent color here).+**S1 gate passed.** Every criterion is met on this machine: looks,+smoothness, startup, memory with a window and in tray mode, event+throughput, Mica, zero-copy video and the ARM64 build.++Still open, carried into later work:+- Run the ARM64 build on ARM64 hardware (CI `windows-11-arm` runner).+- S2 replaces the test pattern with the hardware H.264/H.265 decoder+ (NV12 → RGBA via the D3D11 video processor, into the same shared texture).+- The real app needs a custom title bar so Mica runs edge to edge (the+ system caption is drawn in the accent color here).diff --git a/spikes/s1-qt-rust/build.rs b/spikes/s1-qt-rust/build.rsindex 0d2dfa4..278a9ba 100644--- a/spikes/s1-qt-rust/build.rs+++ b/spikes/s1-qt-rust/build.rs@@ -3,6 +3,7 @@ use cxx_qt_build::{CxxQtBuilder, QmlFile, QmlModule};fn main() {CxxQtBuilder::new_qml_module(QmlModule::new("app.nectarlink.spike").qml_files([+ QmlFile::from("qml/App.qml"),QmlFile::from("qml/Main.qml"),QmlFile::from("qml/Theme.qml").singleton(true),QmlFile::from("qml/Icon.qml"),@@ -17,6 +18,7 @@ fn main() {.cpp_files(["cpp/window_helpers.cpp","cpp/frame_notifier.cpp",+ "cpp/memory_tools.h","cpp/video_surface.h","cpp/video_surface.cpp",])diff --git a/spikes/s1-qt-rust/cpp/memory_tools.h b/spikes/s1-qt-rust/cpp/memory_tools.hnew file mode 100644index 0000000..16b10ce--- /dev/null+++ b/spikes/s1-qt-rust/cpp/memory_tools.h@@ -0,0 +1,27 @@+// SPDX-License-Identifier: GPL-3.0-or-later+#pragma once++#include <QtCore/QObject>+#include <QtQml/QQmlEngine>+#include <QtQml/qqmlregistration.h>++// Releases memory the QML engine keeps after windows are destroyed.+class MemoryTools : public QObject+{+ Q_OBJECT+ QML_ELEMENT+ QML_SINGLETON++public:+ using QObject::QObject;++ // Collects garbage and drops compiled components that have no live+ // instances (the main window's types after it is closed).+ Q_INVOKABLE void trimEngineCaches()+ {+ if (QQmlEngine *engine = qmlEngine(this)) {+ engine->collectGarbage();+ engine->trimComponentCache();+ }+ }+};diff --git a/spikes/s1-qt-rust/cpp/window_helpers.cpp b/spikes/s1-qt-rust/cpp/window_helpers.cppindex 6fc89ea..d9983f3 100644--- a/spikes/s1-qt-rust/cpp/window_helpers.cpp+++ b/spikes/s1-qt-rust/cpp/window_helpers.cpp@@ -2,6 +2,7 @@#include "window_helpers.h"#include <QtCore/QtEnvironmentVariables>+#include <QtGui/QGuiApplication>#include <QtQuick/QQuickWindow>void enable_window_alpha()@@ -14,3 +15,8 @@ void enable_window_alpha()// has no redirection surface. Without this, transparent pixels are white.qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");}++void set_quit_on_last_window_closed(bool quit)+{+ QGuiApplication::setQuitOnLastWindowClosed(quit);+}diff --git a/spikes/s1-qt-rust/cpp/window_helpers.h b/spikes/s1-qt-rust/cpp/window_helpers.hindex e09a1a4..676aa3a 100644--- a/spikes/s1-qt-rust/cpp/window_helpers.h+++ b/spikes/s1-qt-rust/cpp/window_helpers.h@@ -4,3 +4,6 @@// Prepares Qt Quick windows for a DWM system backdrop (Mica). Must be called// before QGuiApplication and any QQuickWindow are created.void enable_window_alpha();++// Keeps the process running with no windows (tray mode).+void set_quit_on_last_window_closed(bool quit);diff --git a/spikes/s1-qt-rust/qml/App.qml b/spikes/s1-qt-rust/qml/App.qmlnew file mode 100644index 0000000..8a8b90d--- /dev/null+++ b/spikes/s1-qt-rust/qml/App.qml@@ -0,0 +1,58 @@+import QtQuick+import app.nectarlink.spike++// Application root. Windows are created on demand and destroyed when closed,+// so the always-running part (core + tray) carries no window or GPU cost.+QtObject {+ id: app++ property Window mainWindow: null+ readonly property Component mainComponent: Component { Main {} }++ function openMain() {+ if (!mainWindow)+ mainWindow = mainComponent.createObject(null)+ }+ function closeMain() {+ if (mainWindow) {+ mainWindow.destroy()+ mainWindow = null+ }+ }++ // --no-window starts straight into tray mode (measures the floor).+ Component.onCompleted: {+ if (Qt.application.arguments.indexOf("--no-window") < 0)+ openMain()+ }++ // --tray-test: open the main window, close it, and report the memory of+ // each state. Measured in-process, so the numbers match Task Manager.+ readonly property bool trayTest: Qt.application.arguments.indexOf("--tray-test") >= 0+ readonly property DeviceModel probe: DeviceModel {}+ property string report: ""++ function sample(label) {+ probe.refreshMemory()+ report += " " + label + "_ws=" + probe.workingSetMb.toFixed(1)+ + " " + label + "_private=" + probe.privateMb.toFixed(1)+ }++ readonly property Timer trayStep1: Timer {+ running: app.trayTest; interval: 3000+ onTriggered: { app.sample("window"); app.closeMain(); app.trayStep2.start() }+ }+ readonly property Timer trayStep2: Timer {+ interval: 3000+ onTriggered: { MemoryTools.trimEngineCaches(); app.sample("tray"); app.trayStep3.start() }+ }+ readonly property Timer trayStep3: Timer {+ interval: 1000+ onTriggered: {+ app.probe.trimWorkingSet()+ app.sample("tray_trimmed")+ console.log("TRAYTEST" + app.report)+ Qt.quit()+ }+ }+}diff --git a/spikes/s1-qt-rust/src/bridge.rs b/spikes/s1-qt-rust/src/bridge.rsindex eadfee1..4010bb8 100644--- a/spikes/s1-qt-rust/src/bridge.rs+++ b/spikes/s1-qt-rust/src/bridge.rs@@ -36,6 +36,7 @@ pub mod qobject {#[qproperty(i32, events_per_second)]#[qproperty(f64, events_total)]#[qproperty(f64, working_set_mb)]+ #[qproperty(f64, private_mb)]#[qproperty(f64, startup_ms)]#[qproperty(bool, stress_running)]type DeviceModel = super::DeviceModelRust;@@ -51,9 +52,15 @@ pub mod qobject {#[qinvokable]fn first_frame(self: Pin<&mut DeviceModel>);+ /// Updates `working_set_mb` and `private_mb`.#[qinvokable]fn refresh_memory(self: Pin<&mut DeviceModel>);+ /// Asks Windows to page out what the process isn't using (what it+ /// does anyway under memory pressure). Used after closing windows.+ #[qinvokable]+ fn trim_working_set(self: Pin<&mut DeviceModel>);+/// A phone notification arrived.#[qsignal]fn notification(self: Pin<&mut DeviceModel>, app: QString, title: QString, body: QString);@@ -73,6 +80,7 @@ pub struct DeviceModelRust {events_per_second: i32,events_total: f64,working_set_mb: f64,+ private_mb: f64,startup_ms: f64,stress_running: bool,stop: Option<Arc<AtomicBool>>,@@ -88,6 +96,7 @@ impl Default for DeviceModelRust {events_per_second: 0,events_total: 0.0,working_set_mb: 0.0,+ private_mb: 0.0,startup_ms: 0.0,stress_running: false,stop: None,@@ -247,29 +256,68 @@ impl qobject::DeviceModel {self.refresh_memory();}- pub fn refresh_memory(self: Pin<&mut Self>) {- let mb = working_set_mb();- self.set_working_set_mb(mb);+ pub fn refresh_memory(mut self: Pin<&mut Self>) {+ let usage = memory_usage();+ self.as_mut().set_working_set_mb(usage.working_set_mb);+ self.set_private_mb(usage.private_mb);+ }++ pub fn trim_working_set(self: Pin<&mut Self>) {+ trim_working_set();+ self.refresh_memory();}}+#[derive(Default)]+struct MemoryUsage {+ /// Physical memory in use (what most tools call "memory").+ working_set_mb: f64,+ /// Committed private memory: what the process really owns.+ private_mb: f64,+}+#[cfg(windows)]#[allow(unsafe_code)]-fn working_set_mb() -> f64 {+fn memory_usage() -> MemoryUsage {use windows::Win32::System::{- ProcessStatus::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},+ ProcessStatus::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, PROCESS_MEMORY_COUNTERS_EX},Threading::GetCurrentProcess,};- let mut counters = PROCESS_MEMORY_COUNTERS {- cb: std::mem::size_of::<PROCESS_MEMORY_COUNTERS>() as u32,+ const MB: f64 = 1024.0 * 1024.0;+ let mut counters = PROCESS_MEMORY_COUNTERS_EX {+ cb: std::mem::size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32,..Default::default()};- // SAFETY: valid pseudo-handle and a correctly sized, writable struct.- let ok = unsafe { GetProcessMemoryInfo(GetCurrentProcess(), &mut counters, counters.cb) };- if ok.is_ok() { counters.WorkingSetSize as f64 / (1024.0 * 1024.0) } else { 0.0 }+ // SAFETY: valid pseudo-handle; the EX struct starts with the base struct+ // and `cb` tells the API which one it is.+ let ok = unsafe {+ GetProcessMemoryInfo(+ GetCurrentProcess(),+ std::ptr::from_mut(&mut counters).cast::<PROCESS_MEMORY_COUNTERS>(),+ counters.cb,+ )+ };+ if ok.is_err() {+ return MemoryUsage::default();+ }+ MemoryUsage {+ working_set_mb: counters.WorkingSetSize as f64 / MB,+ private_mb: counters.PrivateUsage as f64 / MB,+ }+}++#[cfg(windows)]+#[allow(unsafe_code)]+fn trim_working_set() {+ use windows::Win32::System::{ProcessStatus::EmptyWorkingSet, Threading::GetCurrentProcess};+ // SAFETY: valid pseudo-handle for this process.+ let _ = unsafe { EmptyWorkingSet(GetCurrentProcess()) };}#[cfg(not(windows))]-fn working_set_mb() -> f64 {- 0.0+fn memory_usage() -> MemoryUsage {+ MemoryUsage::default()}++#[cfg(not(windows))]+fn trim_working_set() {}diff --git a/spikes/s1-qt-rust/src/main.rs b/spikes/s1-qt-rust/src/main.rsindex b6ecb99..0a974a5 100644--- a/spikes/s1-qt-rust/src/main.rs+++ b/spikes/s1-qt-rust/src/main.rs@@ -21,8 +21,12 @@ fn main() {if let Some(app) = app.as_mut() {app.set_application_name(&QString::from("Nectarlink S1"));}+ // The tray test closes the main window and keeps running, like tray mode.+ if std::env::args().any(|a| a == "--tray-test") {+ native::ffi::set_quit_on_last_window_closed(false);+ }if let Some(engine) = engine.as_mut() {- engine.load(&QUrl::from("qrc:/qt/qml/app/nectarlink/spike/qml/Main.qml"));+ engine.load(&QUrl::from("qrc:/qt/qml/app/nectarlink/spike/qml/App.qml"));}if mica {mica::apply_to_process_windows();diff --git a/spikes/s1-qt-rust/src/native.rs b/spikes/s1-qt-rust/src/native.rsindex b911b41..a193348 100644--- a/spikes/s1-qt-rust/src/native.rs+++ b/spikes/s1-qt-rust/src/native.rs@@ -9,5 +9,8 @@ pub mod ffi {/// Prepares windows for a DWM backdrop. Must be called before/// QGuiApplication and any QQuickWindow are created.fn enable_window_alpha();++ /// Keeps the process running with no windows (tray mode).+ fn set_quit_on_last_window_closed(quit: bool);}}