Skip to content

Optimize CharMap constructor allocations#5422

Merged
tig merged 3 commits into
developfrom
copilot/review-built-in-view-types-memory-optimizations
May 27, 2026
Merged

Optimize CharMap constructor allocations#5422
tig merged 3 commits into
developfrom
copilot/review-built-in-view-types-memory-optimizations

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

Fixes

CharMap eagerly built full Unicode row indexes during construction, making it one of the largest built-in View allocations. This changes the default path to compute row positions on demand while preserving filtered Unicode-category behavior.

Proposed Changes/Todos

  • Avoid default List/Dictionary row-index allocation in CharMap
  • Use arithmetic row mapping for unfiltered Unicode rows
  • Keep lazy row-index collections for ShowUnicodeCategory
  • Add coverage for default allocation behavior and filtered row rebuilds
if (!ShowUnicodeCategory.HasValue)
{
    _visibleRowStarts = null;
    _rowStartToVisibleIndex = null;
    SetContentSize (...);
    return;
}

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

Copilot AI changed the title [WIP] Review built-in View types for memory optimizations Optimize CharMap constructor allocations May 26, 2026
Copilot finished work on behalf of tig May 26, 2026 20:26
Copilot AI requested a review from tig May 26, 2026 20:26
@tig tig marked this pull request as ready for review May 27, 2026 04:29
@tig tig requested a review from BDisp May 27, 2026 14:45
Copy link
Copy Markdown
Collaborator

@BDisp BDisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I had previously encountered an exception when navigating surrogate codepoints between 0xD800 and 0xDFFF, but this fix will prevent that from happening again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review built-in View types for obvious memory optimizations

3 participants