optimize

Replace C# if/switch chains with dictionary dispatch tables.

Updated Jun 3, 2026
One-click install
npx skills add https://github.com/antigravityos187-sketch/universal-or-strategy --skill optimize-antigravityos187-sketch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimize
Source: https://github.com/antigravityos187-sketch/universal-or-strategy/tree/main/.bob/skills/optimize
Command: npx skills add https://github.com/antigravityos187-sketch/universal-or-strategy --skill optimize-antigravityos187-sketch

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill automates the process of replacing complex if/switch chains with dictionary dispatch tables, improving code efficiency and maintainability.

Core Features & Use Cases

  • Branch Elimination: Converts if/switch chains into pre-built dispatch tables for O(1) dispatch.
  • Performance Improvement: Reduces CPU hot path mispredictions and improves runtime performance.
  • Code Maintainability: Easier to extend with new cases by adding dictionary entries.
  • Use Case: Ideal for optimizing critical sections of code where performance and maintainability are paramount.

Quick Start

Run the optimize skill on your code file 'hotpathmethod.cs' to identify and replace switch chains.

Frequently Asked Questions about optimize

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace switch chains with dictionary dispatch tables in C#?

Replace switch chains with dictionary dispatch tables by automating the identification of if/switch statements in C# code and converting them into pre-built dictionary lookups for O(1) dispatch. This eliminates branch mispredictions and improves runtime performance.

What is dictionary dispatch and how does it improve C# code performance?

Dictionary dispatch is an optimization technique that substitutes complex if/switch chains with pre-built hash tables, achieving O(1) lookup times. It significantly reduces CPU hot path mispredictions and improves overall runtime efficiency in critical code sections.

Does dictionary dispatch optimization work with .NET 4.8 and .NET 8.0 environments?

Yes, dictionary dispatch optimization targets both .NET 4.8 and .NET 8.0 environments. It supports Jane Street dispatch patterns and requires analysis of hot path methods alongside post-edit auditing to ensure valid performance improvements.

What's the best way to eliminate branch chains in C# hot paths?

The best way to eliminate branch chains in C# hot paths is converting complex if/switch statements into dictionary-based dispatch tables. This approach improves code maintainability by allowing new cases to be added as simple dictionary entries.

When should I not use dictionary dispatch to optimize C# code?

Dictionary dispatch optimization should be avoided when dealing with simple, infrequent branches that do not justify the memory overhead of pre-built hash tables. It is specifically designed for critical code sections where performance and maintainability are paramount.

How do I run branch elimination on a specific C# file?

Run the optimization process directly on your target C# file, such as 'hotpathmethod.cs', to automatically identify and replace existing if/switch chains with efficient dictionary-based dispatch tables for immediate performance gains.