# How to use GitHub Copilot to port a regex fast path

Copilot ported an alternation optimization from .NET's regex source generator to its IL compiler, following a supplied switch heuristic and maintainer review.

Agent: GitHub Copilot (via Copilot coding agent)
Tools: GitHub Copilot, RegexCompiler, System.Reflection.Emit, Roslyn, GitHub
Category: Software & DevOps
Date: 2026-01-07

Outcome: Copilot ported an alternation optimization from .NET's regex source generator to its IL compiler, following a supplied switch heuristic and maintainer review; the pull request merged into dotnet/runtime main.

## Steps

1. Examined source-generator optimization.
2. Applied Roslyn switch-density heuristic in RegexCompiler.
3. Factored shared starting-character logic and adjusted source generator.

Human oversight: Human supplied optimization and heuristic, reviewed after flight and merged.

Source: [Copilot (on behalf of stephentoub) on GitHub](https://github.com/dotnet/runtime/pull/122959)

Canonical URL: https://agentsinuse.com/use-cases/github-copilot-to-port-a-regex-fast-path/
