Fix large file memory explosion (Issue #457)#498
Closed
Lcstyle wants to merge 10 commits intopop-os:masterfrom
Closed
Fix large file memory explosion (Issue #457)#498Lcstyle wants to merge 10 commits intopop-os:masterfrom
Lcstyle wants to merge 10 commits intopop-os:masterfrom
Conversation
…backup capabilities
Root cause: cosmic-text's shape_until_scroll() uses INFINITY as scroll_end when buffer height is not set, causing ALL lines to be shaped on file load. Each character requires ~200 bytes of glyph/layout data, so a 60MB file was consuming 18.8GB RAM (313x multiplier). Fix: Set a minimal buffer height (100px) before loading files >1MB. This limits initial shaping to ~5 visible lines instead of all lines. The proper height is set during rendering, and additional lines are shaped on-demand as user scrolls. Results: - Before: 60MB file -> 18.8GB RAM (crashes on 8-16GB systems) - After: 60MB file -> 0.2GB RAM (94x memory reduction) Also includes PR pop-os#479 Save As fix: - Added resolve_path() helper for canonical path resolution - Added set_path() and save_as() methods to EditorTab - SaveAsResult now checks if file is already open in another tab Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
For files larger than the configurable threshold (default 5MB), skip the FNV-1a hash computation which iterates over every byte. This eliminates startup lag for large files. Features disabled for large files: - Undo-to-saved detection (check_and_reset_if_unchanged) - Backup content change detection New config option: max_hash_file_size_mb - Default: 5 MB - Set to 0 to always compute hash (not recommended for large files) - Configurable per-user in cosmic-edit settings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
Author
|
Closing in favor of cleaner, separate PRs:
This addresses the review feedback about having too many unrelated commits in one PR. |
Author
|
@mmstick it might be a little messy but I am running the updated build locally, loads 200mb instantly, scroll bar works, no more OOM crashes.. I'm not a RUST developer so please have mercy on the code, claude did generate it but the design was mostly mine. BTW Cosmic Desktop is my new primary OS so i need to make this work and make it better everyday. I am running cosmic on Fedora43, thanks for all your hard work so far, it's beautiful and very very fast. |
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.
Summary
Root Cause Analysis
Found that
cosmic-text'sshape_until_scroll()usesf32::INFINITYasscroll_endwhen buffer height isn't set. This causes ALL lines to be shaped on file load, before the window even renders.Each character requires ~200 bytes of glyph/layout data:
ShapeGlyph: ~100 bytes (positions, font info, metrics, colors)LayoutGlyph: ~100 bytes (positions, font info, bidi level, etc.)Result: 60MB file × 313x multiplier = 18.8GB RAM → OOM crash on systems with <16GB RAM
Fix
Set a minimal buffer height (100px) before loading files >1MB. This limits initial shaping to ~5 visible lines. The proper height is set during rendering, and additional lines are shaped on-demand as user scrolls.
Results
Test Plan
🤖 Generated with Claude Code