Repository navigation
Reduce idle memory: fonts on demand, trim after a tray start, malloc trim on Linux - #1132
Open
KnifeLemon wants to merge 2 commits into
Open
KnifeLemon wants to merge 2 commits into
KnifeLemon wants to merge 2 commits into
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 on demand. SkiaSharp copies a font opened from a stream into native memory, so all 18 files (37 MB) stayed there from the start. Noto Sans is read first, the rest at the first letter it lacks. Letters end up in the same font as before (tested). - 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, malloc limited to 2 arenas, both 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>
Refs #957. It's unmeasured on Linux and could slow in-process native work such as libvips, so it waits for a real number: the reporter is asked to compare with MALLOC_ARENA_MAX=2. malloc_trim stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Nothing here was measured on Linux (no WSL distribution or Docker on the machine). Every number below is Windows x64, Release, English UI, from one or two runs. 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): Noto Sans first, the rest together at the first letter it lacks. They aren't read one by one because Avalonia scores every font read so far, so a partial set would change the font it picks. A test compares the result against the eager collection, starting from a new collection for each letter and weight.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)
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.
The Korean baseline run isn't comparable: its window closed late, so it was sampled before the trim. An earlier Korean-UI run of main measured 188-190 MB after the trim.
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
FileeFontCollectionTests,MemoryTrimmerTests,NativeMemoryRenderTests,LocalizationResourceTestsandMainWindowReleaseTestspass 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