Skip to content

Core: Avoid unused regex engine in trimmed WASM apps - #14208

Merged
danielchalmers merged 4 commits into
devfrom
trim-regex-engine
Nov 13, 2026
Merged

danielchalmers merged 4 commits into
devfrom
trim-regex-engine

Conversation

@danielchalmers

@danielchalmers danielchalmers commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

A trimmed Blazor WebAssembly app with a MudTextField, MudSelect or MudDataGrid downloads the whole regex parser and interpreter, even when it never uses a regular expression.
Two places kept it reachable:

  • PatternMask ran Regex.IsMatch on every typed character, and every text field can take a mask.
  • Every component registered its keys through KeyMapBuilder's string methods, which also accept "/pattern/" keys.

Now MaskChar.Letter, Digit and LetterOrDigit test the character directly, and MudBlazor's components register keys through internal methods that never build a Regex.
No public API changes.
RegexMask, BlockMask, MultiMask, MudHighlighter, a custom MaskChar and "/pattern/" keys still use the engine, as before.

Download size

Page net10.0 net11.0
Providers only 0 0
MudTextField -88.0 KB -91.3 KB
MudSelect -88.0 KB -92.1 KB
MudButton, MudTextField, MudSelect -86.7 KB -89.3 KB
MudDataGrid -85.1 KB -87.6 KB

Release publish of the blazorwasm template with default trimming, _framework total, brotli.
System.Text.RegularExpressions.wasm drops from about 240 KB to 22.8 KB raw; the rest serves source-generated regexes.
Pages with DateMask, the date, time and color pickers, MudAutocomplete, MudMenu, MudTabs, MudTable and MudNumericField end at the same 22.8 KB.

Behavior

  • Tests check the new matching against the old patterns for every UTF-16 code unit.
  • Headless Chrome, dev against this branch, 934 real key steps on the final commit and 1,401 on earlier ones, across masks, select search, pickers, dialogs and toggles: no differences.
  • Key registrations are also lighter: a list item's six keys allocate 1,504 bytes, against 1,720 on dev (64-bit).
  • Only keys a browser never sends differ: a null key passed to DispatchAsync by hand no longer throws in a dialog or select, and a key containing a line feed no longer matches.

Built-in mask characters and MudBlazor's own key bindings no longer go through Regex.
A trimmed WebAssembly app with a text field, select or data grid drops about 86-88 KB (brotli) of System.Text.RegularExpressions.

- MaskChar.Letter, Digit and LetterOrDigit test the character with char.IsLetter, char.IsDigit and char.IsLetterOrDigit.
  Custom mask characters from the public constructor still match through their expression.
- Components register keys through new internal literal and predicate methods on KeyMapBuilder.
  The public string methods keep their "/pattern/" support.
- The "/./" and "/^[^ ]$/" bindings in the dialog and select become predicates that match the same keys.
@danielchalmers danielchalmers added the performance Related to time/memory/CPU/allocation performance characteristics label Nov 13, 2026

@mudbot mudbot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Moving the built-in mask characters and MudBlazor's own key registrations off the regex engine keeps behavior the same, and all string-based key registrations in the library have been converted. The new tests cover equivalence, case sensitivity and first-match ordering. I found nothing that needs fixing before merge.

@danielchalmers danielchalmers changed the title Core: Stop shipping regex engine to apps that never use it Core: Cut 88 KB from trimmed WebAssembly apps that don't use regex Nov 13, 2026
@danielchalmers danielchalmers changed the title Core: Cut 88 KB from trimmed WebAssembly apps that don't use regex Core: Stop trimmed WebAssembly apps downloading unused regex engine Nov 13, 2026
The literal registrations went through a predicate command, which cost a closure and two delegates per key.
Every checkbox, switch, radio, chip and list item registers several keys, so that added up per instance.
A dedicated command holds the key or key set and the action directly.
@danielchalmers danielchalmers changed the title Core: Stop trimmed WebAssembly apps downloading unused regex engine Core: Avoid downloading unused regex engine in trimmed WebAssembly apps Nov 13, 2026
@danielchalmers danielchalmers changed the title Core: Avoid downloading unused regex engine in trimmed WebAssembly apps Core: Avoid unused regex engine in trimmed WASM apps Nov 13, 2026
@danielchalmers
danielchalmers merged commit 72fc2de into dev Nov 13, 2026
13 checks passed
@danielchalmers
danielchalmers deleted the trim-regex-engine branch November 13, 2026 18:41
N3rdage pushed a commit to N3rdage/the-library that referenced this pull request Nov 20, 2026
Updated [MudBlazor](https://github.com/MudBlazor/MudBlazor) from 9.13.0
to 9.14.0.

<details>
<summary>Release notes</summary>

_Sourced from [MudBlazor's
releases](https://github.com/MudBlazor/MudBlazor/releases)._

## 9.14.0

> [!NOTE]
> MudBlazor now targets `net11.0` alongside .NET 8, 9 and 10.

<!-- Release notes generated using configuration in .github/release.yml
at dev -->

## What's Changed
### New Features
* MudDataGrid: Expose filter operator lookup by data type by
@​xiaoyao-666-coder in MudBlazor/MudBlazor#14144
* Core: Add .NET 11 target by @​danielchalmers in
MudBlazor/MudBlazor#14170
* MudVirtualize: Add ItemComparer on .NET 11 by @​danielchalmers in
MudBlazor/MudBlazor#14191
* MudNavLink: Add RelativeToCurrentUri on .NET 11 by @​danielchalmers in
MudBlazor/MudBlazor#14192
* MudDrawer: Add OnBreakpointChanged event by @​versile2 in
MudBlazor/MudBlazor#13021
* MudDataGrid: Add bindable column order state and order event by
@​versile2 in MudBlazor/MudBlazor#12827
* MudFileUpload: Add folder upload support and relative path tracking by
@​drewe7192 in MudBlazor/MudBlazor#13854
* MudNavigationBar: New component by @​mckaragoz in
MudBlazor/MudBlazor#11318
### Bug Fixes
* MudDialog: Fix close button positioned outside dialog by
@​danielchalmers in MudBlazor/MudBlazor#14206
* Converters: Fix TimeOnly fields rejecting input without a Format by
@​danielchalmers in MudBlazor/MudBlazor#14210
* MudDialog: Fix inline dialog ignoring OnKeyDown and OnKeyUp by
@​danielchalmers in MudBlazor/MudBlazor#14211
* MudDataGrid: Keep rows when a Guid filter has no value by @​b84330808
in MudBlazor/MudBlazor#14135
* MudForm: Invoke OnEnterPressed after inputs commit their value by
@​BurakErdemci in MudBlazor/MudBlazor#13840
* MudSplitPanel: Apply divider calls made before panel is ready by
@​danielchalmers in MudBlazor/MudBlazor#14228
* MudFileUpload: Keep selected files when appending too many by
@​danielchalmers in MudBlazor/MudBlazor#14229
* MudFileUpload: Clear errors from previous selection by
@​danielchalmers in MudBlazor/MudBlazor#14230
* MudTable: Keep MultiSelection checkbox in place on small screens by
@​danielchalmers in MudBlazor/MudBlazor#14233
* Charts: Remeasure axis labels for charts hidden at first render by
@​danielchalmers in MudBlazor/MudBlazor#14234
* Core: Revert recognising parent height set in stylesheet by
@​danielchalmers in MudBlazor/MudBlazor#14238
* MudMask: Fix focus loop in Blazor Hybrid after host window loses focus
by @​Primeteumm in MudBlazor/MudBlazor#14237
* MudDataGrid: Cancel form edits closed by backdrop click or Escape by
@​danielchalmers in MudBlazor/MudBlazor#14242
* MudTimePicker: Fix JS error when clock opens and closes in one render
by @​danielchalmers in MudBlazor/MudBlazor#14243
### Accessibility
* MudDataGrid: Show header controls on keyboard focus by @​DevonEast in
MudBlazor/MudBlazor#13899
* MudColorPicker: Add accessible names to channel inputs by
@​danielchalmers in MudBlazor/MudBlazor#14226
* MudList: Use tree roles for nested lists by @​danielchalmers in
MudBlazor/MudBlazor#14231
### Performance
* MudDataGrid: Stop tracking Items collection no longer in use by
@​danielchalmers in MudBlazor/MudBlazor#14207
* Core: Avoid unused regex engine in trimmed WASM apps by
@​danielchalmers in MudBlazor/MudBlazor#14208

## New Contributors
* @​xiaoyao-666-coder made their first contribution in
MudBlazor/MudBlazor#14144
* @​b84330808 made their first contribution in
MudBlazor/MudBlazor#14135
* @​DevonEast made their first contribution in
MudBlazor/MudBlazor#13899
* @​BurakErdemci made their first contribution in
MudBlazor/MudBlazor#13840
* @​drewe7192 made their first contribution in
MudBlazor/MudBlazor#13854
* @​Primeteumm made their first contribution in
MudBlazor/MudBlazor#14237

**Full Changelog**:
MudBlazor/MudBlazor@v9.13.0...v9.14.0

Commits viewable in [compare
view](MudBlazor/MudBlazor@v9.13.0...v9.14.0).
</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Related to time/memory/CPU/allocation performance characteristics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant