maui performance-hotpaths.instructions.md

Coding rules for performance-sensitive parts of .NET MAUI, a framework for building mobile and desktop apps with C#. They focus on code that runs frequently, such as layout, scrolling, touch handling, and list-item recycling.

In plain words
What is it for?
Use them when changing layout measurement, scrolling callbacks, data binding, property notifications, CollectionView or CarouselView recycling, ScrollView code, or other allocation-sensitive handlers.
Why use it?
They help avoid repeated memory allocations and expensive work in frequently called code, which can otherwise cause slow scrolling or a less responsive interface.

Instructions file for GitHub Copilot

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/dotnet/maui/performance-hotpaths
Clone the repo
git clone --depth 1 https://github.com/dotnet/maui

Made for: GitHub Copilot.

Per session 441 This file is loaded in full into every session.
When invoked 441 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00441 $0.00441
Opus 5 $0.00220 $0.00220
Sonnet 5 $0.00088 $0.00088
Haiku 4.5 $0.00044 $0.00044

Measured 2d ago against content hash 5ea9380b4959, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

maui performance-hotpaths.instructions.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/instructions/performance-hotpaths.instructions.md · 35 lines

What it actually says

Performance-Critical Path Rules

Scope rationale: globs target the actual hot paths — layout measure/arrange, platform scroll/touch callbacks, CollectionView/CarouselView (Items + Items2) recycling, and ScrollView. The full handler tree is intentionally NOT included; most handlers (Button, DatePicker, CheckBox, …) are not hot paths and don't need these constraints. If you're working on a handler that IS allocation-sensitive (image decoding, animation tick, etc.), apply these rules anyway.

Hot Paths in MAUI

Measure/arrange cycles, scrolling callbacks, binding propagation, and property change notifications are called at high frequency. All rules below apply to code on these paths.

Allocation Avoidance

  • No LINQ methods (.Where, .Select, .FirstOrDefault, .ToList) — use indexed for loops
  • No closures or lambdas that capture variables — these allocate a compiler-generated class per invocation
  • No string concatenation or interpolation — use StringBuilder or pre-allocated strings if logging is required
  • Prefer Count + indexer over IEnumerable iteration to avoid enumerator allocation

Caching and Invalidation

  • Cache results of expensive computations called multiple times per layout pass
  • Invalidate caches when inputs change — stale caches cause incorrect layout
  • Skip redundant work: if a property's new value equals the old value, do not trigger layout invalidation or re-render

Collection Iteration

  • When the source implements IList or IReadOnlyList, use for (int i = 0; i < list.Count; i++) instead of foreach
  • ObservableCollection change handlers should process only the affected range, not re-enumerate the entire collection
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 35 lines · 441 tokens per session scan A 5ea9380b4959

Subscribe to this mod's changes

maui performance-hotpaths.instructions.md is an instructions file published in the GitHub repository dotnet/maui (23,317 stars, last pushed 2d ago), licensed MIT. It adds 441 tokens to every session, about $0.0022 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other instructions, from other repositories