Skip to content

deonmenezes/mobile-app-skill / skills/swiftui-expert-skill

swiftui-expert-skill

Verified

Use when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state and `@Observable` data flow, view composition, resizable layouts, safe areas, display scale, performance, lists, environment, localization, animation, Liquid Glass, and API migration. Also use for iPhone Duo, foldable, or large-display layouts (`NavigationSplitView` on large displays, iPhone tab sidebar, two-column reflow, foldable grids, `ArrangementView`, `ReservedRegion`), hinge effects, vertical bars, `@State` initialization or synthesized-property diagnostics, `@ContentBuilder` ambiguity, `reorderable` drag/drop, custom `AsyncImage` `URLSession`, swipe actions outside List, item-bound `alert`/`confirmationDialog`, `ToolbarOverflowMenu`, `AnimatableValues`, Document APIs (`Document`/`DocumentReader`), and Instruments `.trace` capture or analysis.

FileKindSize
SKILL.mdskill md11.4 KB
agents/openai.yamlconfig228 B
assets/logo-small.pngbinary29.0 KB
assets/logo.pngbinary389.5 KB
assets/logo.svgother2.0 KB
references/accessibility-patterns.mdmarkdown5.9 KB
references/animation-advanced.mdmarkdown11.2 KB
references/animation-basics.mdmarkdown6.7 KB
references/animation-transitions.mdmarkdown7.9 KB
references/charts-accessibility.mdmarkdown6.1 KB
references/charts.mdmarkdown16.8 KB
references/document-apps.mdmarkdown11.1 KB
references/environment-patterns.mdmarkdown7.1 KB
references/focus-patterns.mdmarkdown8.7 KB
references/image-optimization.mdmarkdown10.4 KB
references/iphone-duo.mdmarkdown7.4 KB
references/latest-apis.mdmarkdown24.8 KB
references/layout-best-practices.mdmarkdown20.6 KB
references/liquid-glass.mdmarkdown12.4 KB
references/list-patterns.mdmarkdown20.5 KB
references/localization.mdmarkdown9.7 KB
references/macos-scenes.mdmarkdown9.5 KB
references/macos-views.mdmarkdown10.8 KB
references/macos-window-styling.mdmarkdown8.6 KB
references/modifier-patterns.mdmarkdown2.5 KB
references/performance-patterns.mdmarkdown11.7 KB
references/previews.mdmarkdown8.1 KB
references/scroll-patterns.mdmarkdown10.6 KB
references/sheet-navigation-patterns.mdmarkdown15.0 KB
references/soft-deprecation.mdmarkdown2.9 KB
references/state-management.mdmarkdown21.5 KB
references/styled-text-editing.mdmarkdown8.7 KB
references/text-patterns.mdmarkdown1.6 KB
references/toolbar-patterns.mdmarkdown9.9 KB
references/trace-analysis.mdmarkdown14.1 KB
references/trace-recording.mdmarkdown5.8 KB
references/view-structure.mdmarkdown28.3 KB
references/webkit-integration.mdmarkdown9.5 KB
scripts/analyze_trace.pyscript9.9 KB
scripts/instruments_parser/__init__.pyscript69 B
scripts/instruments_parser/causes.pyscript5.9 KB
scripts/instruments_parser/correlate.pyscript6.2 KB
scripts/instruments_parser/events.pyscript10.6 KB
scripts/instruments_parser/hangs.pyscript3.4 KB
scripts/instruments_parser/hitches.pyscript4.5 KB
scripts/instruments_parser/summary.pyscript9.1 KB
scripts/instruments_parser/swiftui.pyscript6.6 KB
scripts/instruments_parser/time_profiler.pyscript4.3 KB
scripts/instruments_parser/xctrace.pyscript3.5 KB
scripts/instruments_parser/xml_utils.pyscript7.4 KB
scripts/record_trace.pyscript10.6 KB

scripts/instruments_parser/correlate.py

View on GitHub
"""Cross-lane correlation: for each hang and top-N worst hitches, aggregate
Time Profiler samples and SwiftUI updates whose timestamps fall inside the
event window [start, start+duration]. Uses bisect so lookups stay O(log N)
per event.
"""
from __future__ import annotations

from bisect import bisect_left, bisect_right
from collections import defaultdict
from typing import Any


def build(lanes: dict[str, dict], top_hitches: int = 5, top_symbols: int = 5) -> list[dict]:
    """Produce a list of correlation entries.

    `lanes` is a dict keyed by lane name (time-profiler, hangs, hitches,
    swiftui) of their analyzer outputs.
    """
    tp = lanes.get("time-profiler")
    hangs = lanes.get("hangs")
    hitches = lanes.get("hitches")
    swiftui = lanes.get("swiftui")

    tp_index = _build_time_profile_index(tp)
    sui_events = (swiftui or {}).get("_events") if swiftui and swiftui.get("available") else None

    correlations: list[dict] = []

    if hangs and hangs.get("available"):
        for h in hangs.get("_events", []):
            correlations.append(
                _correlate_event(
                    trigger_lane="hangs",
                    start_ns=h["start_ns"],
                    end_ns=h["end_ns"],
                    extra={"hang_type": h["hang_type"]},
                    tp_index=tp_index,
                    sui_events=sui_events,
                    top_symbols=top_symbols,
                )
            )

    if hitches and hitches.get("available"):
        worst_hitches = hitches.get("_events", [])[:top_hitches]
        for hi in worst_hitches:
            correlations.append(
                _correlate_event(
                    trigger_lane="hitches",
                    start_ns=hi["start_ns"],
                    end_ns=hi["end_ns"],
                    extra={
                        "frame_duration_ms": hi["frame_duration_ms"],
                        "hitch_duration_ms": hi["hitch_duration_ms"],
                    },
                    tp_index=tp_index,
                    sui_events=sui_events,
                    top_symbols=top_symbols,
                )
            )

    return correlations


# --- Internal -------------------------------------------------------------

def _build_time_profile_index(tp: dict | None):
    if not tp or not tp.get("available"):
        return None
    samples = tp.get("_samples") or []
    if not samples:
        return None
    # Samples are already sorted by time in time_profiler.analyze.
    times = [s["time_ns"] for s in samples]
    return {"times": times, "samples": samples}


def _correlate_event(
    trigger_lane: str,
    start_ns: int,
    end_ns: int,
    extra: dict,
    tp_index: dict | None,
    sui_events: list[dict] | None,
    top_symbols: int,
) -> dict[str, Any]:
    entry: dict[str, Any] = {
        "trigger": {
            "lane": trigger_lane,
            "start_ms": round(start_ns / 1_000_000, 2),
            "end_ms": round(end_ns / 1_000_000, 2),
            "duration_ms": round((end_ns - start_ns) / 1_000_000, 2),
            **extra,
        },
    }

    if tp_index is not None:
        tp = _time_profile_hot_symbols(
            tp_index, start_ns, end_ns, top_symbols
        )
        duration_ns = end_ns - start_ns
        # Sample rate is 1ms/sample on standard Time Profiler. If the window
        # is N ms long we'd expect ~N main-thread samples if main was fully
        # running; fewer means main was blocked (I/O, lock, etc.).
        expected_if_running = max(1, duration_ns // 1_000_000)
        coverage_pct = min(100.0, 100.0 * tp["samples_main"] / expected_if_running)
        entry["time_profiler_main_thread"] = {
            "samples_in_window": tp["samples_total"],
            "samples_on_main": tp["samples_main"],
            "main_running_coverage_pct": round(coverage_pct, 1),
            "hot_symbols": tp["hot_symbols"],
        }

    if sui_events is not None:
        sui_overlap = _swiftui_overlaps(sui_events, start_ns, end_ns)
        entry["swiftui_overlapping_updates"] = sui_overlap

    return entry


def _time_profile_hot_symbols(
    tp_index: dict, start_ns: int, end_ns: int, top_n: int
) -> dict:
    """Return main-thread hot symbols in the given window.

    Hang/hitch/SwiftUI correlations are all main-thread responsiveness
    problems, so worker-thread symbols are noise. We also return a coverage
    metric — when main was blocked on I/O or a lock, the window will have
    far fewer samples than its duration would predict, and that signal is
    what tells the agent "this was blocked, not CPU-bound".
    """
    times = tp_index["times"]
    samples = tp_index["samples"]
    lo = bisect_left(times, start_ns)
    hi = bisect_right(times, end_ns)
    window = samples[lo:hi]
    if not window:
        return {"samples_total": 0, "samples_main": 0, "hot_symbols": []}

    main_samples = [s for s in window if s["is_main"]]
    weight_by_symbol: dict[str, int] = defaultdict(int)
    count_by_symbol: dict[str, int] = defaultdict(int)
    for s in main_samples:
        weight_by_symbol[s["leaf_symbol"]] += s["weight_ns"]
        count_by_symbol[s["leaf_symbol"]] += 1
    total_weight = sum(weight_by_symbol.values()) or 1

    ranked = sorted(weight_by_symbol.items(), key=lambda kv: kv[1], reverse=True)
    hot = []
    for symbol, weight in ranked[:top_n]:
        hot.append({
            "symbol": symbol,
            "samples": count_by_symbol[symbol],
            "weight_ms": round(weight / 1_000_000, 2),
            "percent_of_main": round(100.0 * weight / total_weight, 2),
        })
    return {
        "samples_total": len(window),
        "samples_main": len(main_samples),
        "hot_symbols": hot,
    }


def _swiftui_overlaps(
    events: list[dict], start_ns: int, end_ns: int
) -> list[dict]:
    # Events aren't guaranteed sorted by start_ns here (we sort by duration in
    # swiftui.analyze). Linear scan; SwiftUI event counts are typically small.
    out: list[dict] = []
    for e in events:
        if e["end_ns"] < start_ns or e["start_ns"] > end_ns:
            continue
        out.append({
            "view": e["view"],
            "duration_ms": e["duration_ms"],
            "start_ms": e["start_ms"],
        })
    # Worst first.
    out.sort(key=lambda x: x["duration_ms"], reverse=True)
    return out[:10]
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall