dart-optimization
Optimize Dart code for performance, type safety, and runtime error prevention. Use when profiling hot paths, enforcing sound typing, handling null safety, or debugging type mismatches and runtime failures.
What this skill does
# Optimization & Debugging
Performance in Dart goes beyond UI rendering; it's about efficient execution, smart resource utilization, and sound error handling.
## Dart Performance Patterns
- **Standardize Types**: Avoid `dynamic`. Use explicit types or `Object?`. Statically typed code allows the compiler to perform far better optimizations.
- **Efficient Collections**:
- Use `Set` for average O(1) containment checks.
- Use `List` for ordered indexing.
- Prefer `Iterable` methods (`map`, `where`) for readability, but use `for` loops in performance-critical hot paths.
- **Inlining**: Small getters and trivial functions are often inlined by the VM/AOT, but keeping them simple ensures this optimization happens.
## Compile-Time Optimizations
- **Final & Const**: Declare variables as `final` whenever possible. Use `const` constructors for widgets and data models to enable compile-time allocation and reduce runtime garbage collection pressure.
- **Ternary vs If-Else**: In Dart, they are generally equivalent, but prioritize readability. Use `switch` expressions (Dart 3+) for exhaustive and efficient pattern matching.
## Hot Paths & Loops
- **Minimize Work in Loops**: Extract calculations and object creations outside of loops.
- **Collection Literals**: Use literal syntax `[]` or `{}` instead of constructors like `List()` for brevity and minor performance gains.
## Type System & Soundness
Enforce Dart's sound type system to prevent runtime invalid states.
- **Method Overrides:** Maintain sound return types (covariant) and parameter types (contravariant). Never tighten a parameter type in a subclass unless explicitly marked with the `covariant` keyword.
- **Generics & Collections:** Add explicit type annotations to generic classes (e.g., `List<T>`). Never assign a `List<dynamic>` to a typed list.
- **Downcasting:** Avoid implicit downcasts from `dynamic`. Use explicit casts (e.g., `as List<Cat>`) when necessary, but ensure the underlying runtime type matches to prevent `TypeError` exceptions.
- **Strict Casts:** Enable `strict-casts: true` in `analysis_options.yaml` to force explicit casting and catch implicit downcast errors at compile time.
## Null Safety & Error Handling
Eliminate static errors related to null safety by correctly managing variable initialization and nullability.
- **Modifiers:** Apply `?` for nullable types, `!` for null assertions, and `required` for named parameters that cannot be null.
- **Late Initialization:** Use the `late` keyword for non-nullable variables guaranteed to be initialized before use.
- **Catching:** Catch `Exception` subtypes for recoverable failures.
- **Errors:** Never explicitly catch `Error` or its subtypes (e.g., `TypeError`, `ArgumentError`). Errors indicate programming bugs that must be fixed, not caught.
- **Rethrowing:** Use `rethrow` inside a `catch` block to propagate an exception while preserving its original stack trace.
## Profiling & Debugging
- **DevTools CPU Profiler**: Identify hot paths and "heavy" functions.
- **Benchmarking**: Use `package:benchmark_harness` for scientific performance measurement of non-UI logic.
- **Hot Reload vs Restart**: Use hot reload for UI changes. For state initialization or deep logic changes that cause runtime errors, use hot restart to clear the state tree.
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.