MudItem: Build only the breakpoint classes that are set - #13738
Merged
danielchalmers merged 2 commits intoAug 27, 2026
Merged
danielchalmers merged 2 commits into
danielchalmers merged 2 commits into
Conversation
Each breakpoint class was passed to AddClass as an interpolated string with its condition alongside, so the string was built whether or not the condition held. Most items set one breakpoint out of six, so five were formatted and thrown away on every render. Building them inside the conditions cuts a 200-item grid from 478 to 416 KB on mount and from 177 to 115 KB on re-render, with identical markup.
This was referenced Sep 14, 2026
This was referenced Sep 14, 2026
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.
Problem
Every breakpoint class was passed to
AddClassas an interpolated string with its condition as a second argument:Arguments are evaluated before the call, so the string is formatted whether or not the condition holds. Most items set one breakpoint out of six, so five are built and thrown away on every render.
Fix
Build each class inside its condition. The markup is unchanged.
Numbers
200
MudItemwith onlyxsset, allocation measured on a bareRendererwithGC.GetTotalAllocatedBytes, median of 5:That is 310 B less per item on re-render, which is the repeated cost.
Scope
Only
MudItem, deliberately. The same pattern appears elsewhere, but measuring it showed the saving comes from formatting a value into the string, not from the interpolation itself, so it only pays where a number or enum is formatted into a class that usually is not used:MudStackhas five conditional interpolated classes and the same change made no measurable difference at all (391 KB and 108 KB either way), because its values are null when unset and a null appends nothing.MudInputCssHelperlikewise: 1026 KB against 1025 KB across a 20 field form.MudIconButtonhas six such classes, but at ~9.9 KB per instance the saving would be under 4%.MudItemstands out because it is a very small component whose class chain is most of what it does, and because six integer breakpoints are formatted where at most a couple are used.Verification
Class output is identical for none,
xs,xs+md, all six breakpoints,xxlonly,xs+Class, andClassonly.The Grid documentation page renders 30 grid items with an identical class string on this branch and on
dev(same hash, same 1053 characters), before and after moving the interactive sliders.361 Grid tests and the full suite pass.