Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set capacity of XAML resource dictionaries #15069

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

MrJul
Copy link
Member

@MrJul MrJul commented Mar 21, 2024

What does the pull request do?

This PR adds a new EnsureCapacity to ResourceDictionary, used to prepare its backing storage for new items.

The XAML compiler now calls this method before adding items to the ResourceDictionary, since it knows how many will be added.

This avoids expanding the capacity several times at startup (for example, FluentTheme has dictionaries with up to 709 items), saving memory allocations.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046428-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul force-pushed the feature/xaml-rd-capacity branch from 7929709 to c82f8a5 Compare March 23, 2024 09:39
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046481-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

/// Ensures that the resource dictionary can hold up to <paramref name="capacity"/> entries without
/// any further expansion of its backing storage.
/// </summary>
/// <remarks>This method may have no effect when targeting .NET Standard 2.0.</remarks>
Copy link
Member

Choose a reason for hiding this comment

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

This remark is partially outdated now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it to "may have" since it's still true that it doesn't do anything when on .NET standard and the inner dictionary is already initialized.

@jmacato jmacato added this pull request to the merge queue Mar 25, 2024
Merged via the queue into AvaloniaUI:master with commit bb6005b Mar 25, 2024
10 checks passed
@MrJul MrJul deleted the feature/xaml-rd-capacity branch March 30, 2024 13:16
@maxkatz6 maxkatz6 added the backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch label Apr 20, 2024
@maxkatz6 maxkatz6 added backported-11.1.x and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants