Repository navigation
Reduce idle memory: fonts on demand, trim after a tray start, malloc trim on Linux - #1132
Merged
Merged
Conversation
…im malloc on Linux Refs #957. Measured on Windows only (a Linux measurement wasn't possible here): the managed heap is 3-7 MB at idle, so GC, JIT and ReadyToRun settings don't matter. Native memory does. - Embedded fonts are read family by family when text asks. SkiaSharp copies a font opened from a stream into native memory, so all 18 files (37 MB) stayed there from the start. FileeFontCollection keeps matching a letter only in the family asked for (#1095), so families later in the chain stay unread. - A start without a window now requests a trim: nothing asked for one before. - The trim uses an aggressive collection: a forced one keeps empty regions committed, contrary to what the comment said. - Linux: malloc_trim after the collections, bound by name so musl is left alone. - Linux: the trim logs own/resident/anonymous memory, the managed heap and malloc, because Process.PrivateMemorySize64 reports VmData there. - Linux: FILEE_RENDERING=software, as the GPU driver stays loaded with no window. - Closing the crop, image edit and PDF page windows also requests a trim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KnifeLemon
force-pushed
the
fix/idle-memory-957
branch
from
November 4, 2026 18:10
5e0f1be to
8437f36
Compare
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.
Refs #957
Filee's memory while waiting in the tray is almost all native, not managed. This PR removes what could safely go and makes the next Linux log show the split. It builds on #1121, which it needs: on-demand fonts rely on a letter being matched only in the family asked for.
Nothing here was measured on Linux (no WSL distribution or Docker on the machine). Every number below is Windows x64, Release, from two runs unless noted. The Linux changes are compiled (
-r linux-x64) but have never been run.What fills idle memory (Windows)
SKTypeface.FromStreamcopies each into native memory (read from its IL, so this also applies on Linux).FILEE_RENDERING=software). Avalonia's GLX setup also creates its context at start (read from its IL).Changes
FileeFontCollection, combined with the wrapper from Draw Han in the UI language's own font #1121): each family is read when the font chain first asks for it. A letter is still matched only in the family asked for, so families later in the chain stay unread: in an English or Korean UI, "→" and Han read Noto Sans KR, and JP and SC stay out.malloc_trimin the trim, looked up by name inlibc.so.6, so musl skips it.Process.PrivateMemorySize64readsVmDatathere, which isn't whatsmemshows.FILEE_RENDERING=software(X11), opt-in. I left the default alone because I can't test the donut's animation on Linux.On Windows and macOS the fonts, the tray-start trim, the aggressive collection and the trim on closing those windows also apply. The Windows trim log line gains the committed size.
Measured (Windows)
The baseline is main before #1121, which reads every font at the start. #1121 itself wasn't measured on its own; it doesn't change what is read.
The working set after closing the window is about 21-26 MB in both builds, because the Windows trim already emptied it.
Freeing a 544 MB managed heap in a separate probe, then trimming:
In one of the two forced runs, committed had dropped to 88 MB three seconds later; in the other it stayed at 422 MB.
Tried at a tray start, no effect beyond noise (about 3 MB), so not changed: ReadyToRun,
TieredPGO=0,TieredCompilation=0,gcConcurrent=0,GCConserveMemory=5,GCgen0size. ReadyToRun also made no difference after the window had been open, and it adds 44 MB to the publish folder.Limits
malloc_trimeffect, and everything else in real Linux numbers. The new log line is there to get them from the reporter.Left out
MALLOC_ARENA_MAX=2first, and will decide from that number.SkiaOptions.MaxGpuResourceSizeBytes: 16 MB saved about 19 MB private, but a low cap risks re-uploading large previews every frame.AnnotationFonts: still keeps its own copies of the bold faces after the first label.Tests
FileeFontCollectionTestsandLocalizationResourceTestspass, including Draw Han in the UI language's own font #1121's expected fonts: zh-CN将in Noto Sans SC, ko in Noto Sans KR, ja in Noto Sans JP. A letter's font is also checked to be the same on a new collection as with every family already read.MemoryTrimmerTestsandNativeMemoryRenderTestspass on Windows.LinuxMemoryTests: the parsing passes here. The glibc test is skipped on Windows, so CI on Linux will be its first run.dotnet format --verify-no-changesis clean on the changed files.🤖 Generated with Claude Code