Repository navigation
macOS: reduce idle memory footprint with windowless tray agents - #50
Closed
mikhail-angelov wants to merge 1 commit into
Closed
mikhail-angelov wants to merge 1 commit into
mikhail-angelov wants to merge 1 commit into
Conversation
Owner
|
Thanks @mikhail-angelov this makes a lot of sense. I am going to get this working using your PR as long as I can make it work cross platform as well. Looking at it now. |
tarwin
added a commit
that referenced
this pull request
Oct 12, 2026
No main window or WebView until the app opens a named one, on macOS, Windows and Linux (#50, macOS by Mikhail Angelov). Linux named windows open with the current app.icon(). Discord link in the README and site. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
Thanks @mikhail-angelov a new release has now been deployed with your changes - and more that help it work in a similar way cross platform. Main thing to know is I changed the setting to |
Owner
|
@mikhail-angelov sorry I screwed up the commit message so it doesn't show as merged - my mistake. Please know this did merge your changes. I'll try better next time - still new to this whole running an open source project thing. |
Contributor
Author
|
thank you |
feiyunwill
pushed a commit
to feiyunwill/tinyjsapp
that referenced
this pull request
Oct 15, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
feiyunwill
pushed a commit
to feiyunwill/tinyjsapp
that referenced
this pull request
Oct 15, 2026
…in#50) - Rename the flag from "headless" to "mainWindow": false (tinyjs.json and createApp). "headless" already means "no display" across the launcher and skill docs; internals follow (g_windowless, TINYJS_NO_MAIN_WINDOW, TinyjsNoMainWindow plist key, test/windowless-tray). - Windows/Linux no longer fail: they keep a hidden main window (accessory activation, blank page when there's no index.html) and the CLI prints a notice, so one tinyjs.json runs everywhere. - Reject "url" combined with "mainWindow": false. - Document why TinyWindowlessDelegate exists (install_open_handlers needs a delegate to attach openURLs/openFiles to). - README, skill docs, types and TODO-verify updated; macOS (arm64 and x86_64 under Rosetta) verified. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
macOS: reduce idle memory footprint with windowless tray agents
Tray apps currently construct a main WKWebView even with accessory activation.
A background filesystem watcher therefore pays for a hidden browser just to
expose its menu-bar icon.
Goals
need a WebView. Keep the backend, native tray and menus available without
constructing a main window or starting WebKit worker processes.
when needed, close its window while the worker stays alive, and open it again.
Applications needing complete editor-process teardown can launch their editor
separately from the windowless agent.
The target is removing the always-on WebView cost. This PR does not establish
5 MiB as a memory budget or guarantee that closing an in-process window releases
all WebKit memory.
Implementation
Add opt-in
headless: trueto macOS configuration and createApp options.Start the native AppKit host and backend without a main window or WebView;
retain native tray commands, named windows, their bridge and close callbacks
on the existing protocol. Frontend/index.html is optional at startup.
Both modes share one AppKit dispatcher and event loop. Only startup
initialization differs; no additional runtime, process or protocol is introduced.
Application visibility works without a main window; headless reload targets
open named pages. Dev skips watching an absent frontend directory, and
missing-window state is nullable in the types.
Dev passes TINYJS_HEADLESS; packaged apps use a TinyjsHeadless plist boolean.
Main-window APIs do not implicitly create a window. Headless named windows
use a native UIDelegate for file-picker and dialog callbacks normally registered
by the webview library during construction of its main view.
Scope and limitations
macOS implementation only. Windows/Linux explicitly reject the enabled flag.
Intel/macOS 14 and Windows/Linux native builds were not run. On-device AI was
disabled for the source build. This is a GUI-session agent, not an SSH/server mode.
WebKit may cache workers after an in-process window closes. Window destruction
and an empty window list therefore do not prove full memory teardown. A separate
editor process is an application-level deployment choice, not a process manager
introduced or automatically configured by this PR.
Evidence against the goals
A paired before/after run was performed on macOS 26.6.2 / Apple Silicon,
txiki.js 26.6.0. The baseline SDK was built from unmodified upstream commit
8336e31d5d03329051b13284730d98f9ec2682ca; the other SDK included this patch.Both launchers were built using
TINYJS_AI=0 ./setup.shand the same toolchain.Both runs used ad-hoc signed packaged apps with the same backend, native tray,
empty index.html, editor.html, window size and accessory activation. The
baseline had no headless flag; the patched app enabled
headless: true.The baseline therefore kept its hidden main WebView, while the patched app
started without one. Both opened and closed the same named editor twice.
The runs were sequential, with the first app exiting before the second began.
Memory is the sum of
Physical footprintfromvmmap -summaryfor the launcher,its backend and newly started WebKit workers observed during that isolated run.
WebKit workers were identified from process snapshots before launch and at each
sample, since their parent PID can be 1. Raw process IDs and command lines were
retained. This method can be confounded by another app starting WebKit at the
same time; it is a local process-snapshot measurement, not system-wide RAM savings.
Values include compressed memory and are not disk size or virtual address space.
Individual vmmap figures are rounded, so totals below are approximate.
The editor opens at 7 s, closes at 15 s, reopens at 24 s and closes again at
32 s. Samples are taken at approximately 4, 11, 19, 28 and 36 s after launch.
Goal 1, lower background footprint: demonstrated. Before the first editor
open, memory fell from 65.29 to 17.17 MiB, approximately 74%.
The baseline had five processes (launcher, backend, GPU, Networking, WebContent);
the patched app had only two (launcher and backend) while its native tray worked.
Goal 2, independent window lifecycle: demonstrated. Both packaged runs
reported a live native tray and successful page bridge/store round trips on both
editor opens. The unpatched run reported
BOOT ["main"],CLOSED ["main"]andCLOSED_AGAIN ["main"]; the patched run reportedBOOT [],CLOSED []andCLOSED_AGAIN []. Both closes emittedWINDOW_CLOSED editor, and the backgroundbackend and tray remained alive. The patched dev path passed the same lifecycle
checks separately.
Full memory teardown after an in-process close is not demonstrated. In the
patched first cycle, WebContent exited but GPU/Networking remained; after the
second close, WebContent was still present at the sample. Neither close restored
the cold-start footprint. This is why the goal is avoiding an always-on main
WebView, with separate editor processes available for strict teardown, rather
than promising that window closure releases all WebKit memory.
Lifecycle reproduction is documented in
test/headless-tray/README.md.For the paired run, identical temporary copies of that fixture included an
empty index.html in both versions to satisfy the baseline's main-page requirement.
The normal headless fixture still deliberately has no index.html.
Raw measurements, per-process vmmap output, build logs, lifecycle logs and the
measurement script are retained locally under
.build/memory-comparison/;these local artifacts are not shipped as part of the PR.
Additional checks passed:
TINYJS_AI=0 ./setup.sh: native macOS ARM64 launcher builds.node --check cli.js,node --check runtime/bridge.js,git diff --check.codesign --verify --deep --strictfor the packaged fixture.["main"]and loads its page.headless mode; this is not a native platform build test.
true/valueon both editor loadsusing the existing native default-button test hook. File-picker and physical
tray clicking remain manual checks in the fixture README.