@nklisch/pi-agile-workflow 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/.claude-plugin/plugin.json +10 -0
  2. package/.codex-plugin/plugin.json +28 -0
  3. package/CHANGELOG.md +591 -0
  4. package/README.md +107 -0
  5. package/docs/ARCHITECTURE.md +716 -0
  6. package/docs/MIGRATION.md +419 -0
  7. package/docs/PRINCIPLES.md +464 -0
  8. package/docs/ROADMAP.md +95 -0
  9. package/docs/SPEC.md +855 -0
  10. package/docs/VISION.md +106 -0
  11. package/extensions/agile-workflow.test.ts +419 -0
  12. package/extensions/agile-workflow.ts +467 -0
  13. package/hooks/hooks.json +52 -0
  14. package/hooks/scripts/prompt-context.py +628 -0
  15. package/hooks/scripts/substrate-maintainer.py +359 -0
  16. package/hooks/scripts/test_prompt_context.py +757 -0
  17. package/package.json +30 -0
  18. package/scripts/install-work-view.sh +165 -0
  19. package/scripts/tests/agent-metadata.test.sh +75 -0
  20. package/scripts/tests/bump-version.test.sh +552 -0
  21. package/scripts/tests/channel-parity.test.sh +117 -0
  22. package/scripts/tests/convert-content-integrity.test.sh +246 -0
  23. package/scripts/tests/convert-install-routing.test.sh +159 -0
  24. package/scripts/tests/install-work-view.test.sh +411 -0
  25. package/scripts/tests/pi-package-metadata.test.sh +119 -0
  26. package/scripts/tests/work-board-shim.test.sh +239 -0
  27. package/scripts/tests/work-view-dist-version.test.sh +105 -0
  28. package/scripts/work-board.sh +64 -0
  29. package/scripts/work-view.sh +423 -0
  30. package/skills/autopilot/SKILL.md +330 -0
  31. package/skills/autopilot/agents/openai.yaml +6 -0
  32. package/skills/board/SKILL.md +62 -0
  33. package/skills/board/agents/openai.yaml +6 -0
  34. package/skills/bold-refactor/SKILL.md +244 -0
  35. package/skills/bold-refactor/agents/openai.yaml +6 -0
  36. package/skills/bug-scan/SKILL.md +378 -0
  37. package/skills/bug-scan/agents/openai.yaml +6 -0
  38. package/skills/bug-scan/references/async-promises.md +119 -0
  39. package/skills/bug-scan/references/concurrency-races.md +148 -0
  40. package/skills/bug-scan/references/data-layer.md +167 -0
  41. package/skills/bug-scan/references/error-handling.md +197 -0
  42. package/skills/bug-scan/references/gate-item-template.md +94 -0
  43. package/skills/bug-scan/references/language-footguns.md +219 -0
  44. package/skills/bug-scan/references/parked-item-template.md +103 -0
  45. package/skills/bug-scan/references/report-template.md +115 -0
  46. package/skills/bug-scan/references/resource-leaks.md +199 -0
  47. package/skills/bug-scan/references/state-closures.md +148 -0
  48. package/skills/bug-scan/references/time-numbers.md +158 -0
  49. package/skills/convert/SKILL.md +1463 -0
  50. package/skills/convert/agents/openai.yaml +6 -0
  51. package/skills/convert/references/legacy-overlap-migration.md +179 -0
  52. package/skills/deep-code-scan/SKILL.md +378 -0
  53. package/skills/deep-code-scan/agents/openai.yaml +6 -0
  54. package/skills/deep-code-scan/references/artifact-ledger.md +148 -0
  55. package/skills/deep-code-scan/references/consolidation.md +91 -0
  56. package/skills/deep-code-scan/references/decomposition.md +127 -0
  57. package/skills/deep-code-scan/references/item-templates.md +263 -0
  58. package/skills/deep-code-scan/references/lane-catalog.md +129 -0
  59. package/skills/deep-code-scan/references/review-gauntlet.md +108 -0
  60. package/skills/deep-code-scan/references/scanner-brief.md +152 -0
  61. package/skills/e2e-test-design/SKILL.md +517 -0
  62. package/skills/e2e-test-design/references/anti-tautology.md +261 -0
  63. package/skills/e2e-test-design/references/service-mocks.md +234 -0
  64. package/skills/e2e-test-design/references/test-taxonomy.md +211 -0
  65. package/skills/epic-design/SKILL.md +476 -0
  66. package/skills/epicize/SKILL.md +210 -0
  67. package/skills/epicize/agents/openai.yaml +6 -0
  68. package/skills/feature-design/SKILL.md +472 -0
  69. package/skills/fix/SKILL.md +173 -0
  70. package/skills/gate-cruft/SKILL.md +258 -0
  71. package/skills/gate-docs/SKILL.md +278 -0
  72. package/skills/gate-patterns/SKILL.md +389 -0
  73. package/skills/gate-refactor/SKILL.md +408 -0
  74. package/skills/gate-security/SKILL.md +275 -0
  75. package/skills/gate-tests/SKILL.md +367 -0
  76. package/skills/groom/SKILL.md +162 -0
  77. package/skills/groom/agents/openai.yaml +6 -0
  78. package/skills/ideate/SKILL.md +185 -0
  79. package/skills/ideate/agents/openai.yaml +6 -0
  80. package/skills/implement/SKILL.md +288 -0
  81. package/skills/implement-orchestrator/SKILL.md +604 -0
  82. package/skills/park/SKILL.md +111 -0
  83. package/skills/perf-design/SKILL.md +427 -0
  84. package/skills/perf-scout/SKILL.md +404 -0
  85. package/skills/perf-scout/agents/openai.yaml +6 -0
  86. package/skills/perf-scout/references/algorithmic-and-data-structures.md +126 -0
  87. package/skills/perf-scout/references/approximation-and-precomputation.md +136 -0
  88. package/skills/perf-scout/references/caching-and-memoization.md +123 -0
  89. package/skills/perf-scout/references/compiler-runtime-and-language.md +136 -0
  90. package/skills/perf-scout/references/database-and-storage-internals.md +144 -0
  91. package/skills/perf-scout/references/distributed-systems.md +150 -0
  92. package/skills/perf-scout/references/game-engine-and-realtime.md +136 -0
  93. package/skills/perf-scout/references/gpu-and-accelerators.md +130 -0
  94. package/skills/perf-scout/references/idea-ranking.md +75 -0
  95. package/skills/perf-scout/references/io-and-batching.md +135 -0
  96. package/skills/perf-scout/references/memory-and-data-locality.md +137 -0
  97. package/skills/perf-scout/references/parallelism-and-vectorization.md +126 -0
  98. package/skills/perf-scout/references/parked-item-template.md +117 -0
  99. package/skills/perf-scout/references/peer-review-pass.md +150 -0
  100. package/skills/perf-scout/references/report-template.md +148 -0
  101. package/skills/principles/SKILL.md +678 -0
  102. package/skills/principles/references/models.md +191 -0
  103. package/skills/principles/references/subagents.md +158 -0
  104. package/skills/prose-author/SKILL.md +185 -0
  105. package/skills/refactor-conventions-creator/SKILL.md +359 -0
  106. package/skills/refactor-conventions-creator/agents/openai.yaml +6 -0
  107. package/skills/refactor-conventions-creator/references/common-structures.md +91 -0
  108. package/skills/refactor-conventions-creator/references/common-styles.md +90 -0
  109. package/skills/refactor-design/SKILL.md +384 -0
  110. package/skills/release-deploy/SKILL.md +667 -0
  111. package/skills/release-deploy/agents/openai.yaml +6 -0
  112. package/skills/research/SKILL.md +166 -0
  113. package/skills/research/agents/openai.yaml +6 -0
  114. package/skills/review/SKILL.md +267 -0
  115. package/skills/review/references/deep-review.md +98 -0
  116. package/skills/review/references/review-lenses.md +68 -0
  117. package/skills/review/references/substrate-side-effects.md +161 -0
  118. package/skills/review/references/target-resolution.md +52 -0
  119. package/skills/scope/SKILL.md +486 -0
  120. package/work-view/Cargo.lock +486 -0
  121. package/work-view/Cargo.toml +9 -0
  122. package/work-view/crates/cli/.work-view-version +1 -0
  123. package/work-view/crates/cli/Cargo.toml +18 -0
  124. package/work-view/crates/cli/src/actionable.rs +500 -0
  125. package/work-view/crates/cli/src/args.rs +792 -0
  126. package/work-view/crates/cli/src/board/assets/board.css +855 -0
  127. package/work-view/crates/cli/src/board/assets/board.js +259 -0
  128. package/work-view/crates/cli/src/board/assets/card.js +139 -0
  129. package/work-view/crates/cli/src/board/assets/components.css +290 -0
  130. package/work-view/crates/cli/src/board/assets/dependency.js +1193 -0
  131. package/work-view/crates/cli/src/board/assets/detail.js +256 -0
  132. package/work-view/crates/cli/src/board/assets/filters.js +389 -0
  133. package/work-view/crates/cli/src/board/assets/index.html +77 -0
  134. package/work-view/crates/cli/src/board/assets/kanban.js +231 -0
  135. package/work-view/crates/cli/src/board/assets/markdown.js +260 -0
  136. package/work-view/crates/cli/src/board/assets/motion.css +131 -0
  137. package/work-view/crates/cli/src/board/assets/state.js +245 -0
  138. package/work-view/crates/cli/src/board/assets/table.js +304 -0
  139. package/work-view/crates/cli/src/board/assets/tokens.css +602 -0
  140. package/work-view/crates/cli/src/board/assets/views.js +41 -0
  141. package/work-view/crates/cli/src/board/assets.rs +162 -0
  142. package/work-view/crates/cli/src/board/feed.rs +204 -0
  143. package/work-view/crates/cli/src/board/mod.rs +246 -0
  144. package/work-view/crates/cli/src/board/open.rs +144 -0
  145. package/work-view/crates/cli/src/board/server.rs +407 -0
  146. package/work-view/crates/cli/src/main.rs +195 -0
  147. package/work-view/crates/cli/src/render.rs +354 -0
  148. package/work-view/crates/cli/src/scope.rs +157 -0
  149. package/work-view/crates/cli/src/stale.rs +581 -0
  150. package/work-view/crates/cli/tests/board-js/dependency-table.test.mjs +64 -0
  151. package/work-view/crates/cli/tests/board-js/expanded-browsing.test.mjs +79 -0
  152. package/work-view/crates/cli/tests/board-js/harness-smoke.test.mjs +11 -0
  153. package/work-view/crates/cli/tests/board-js/harness.mjs +437 -0
  154. package/work-view/crates/cli/tests/board-js/kanban-detail.test.mjs +75 -0
  155. package/work-view/crates/cli/tests/board-js/markdown-filter.test.mjs +60 -0
  156. package/work-view/crates/cli/tests/fixtures/golden/.work/CONVENTIONS.md +3 -0
  157. package/work-view/crates/cli/tests/fixtures/golden/.work/active/epics/epic-alpha.md +16 -0
  158. package/work-view/crates/cli/tests/fixtures/golden/.work/active/features/feat-a.md +16 -0
  159. package/work-view/crates/cli/tests/fixtures/golden/.work/active/features/feat-b.md +16 -0
  160. package/work-view/crates/cli/tests/fixtures/golden/.work/active/stories/story-alpha-1.md +16 -0
  161. package/work-view/crates/cli/tests/fixtures/golden/.work/active/stories/story-research-1.md +19 -0
  162. package/work-view/crates/cli/tests/fixtures/golden/.work/archive/feat-done.md +16 -0
  163. package/work-view/crates/cli/tests/fixtures/golden/.work/archive/feat-shipped.md +18 -0
  164. package/work-view/crates/cli/tests/fixtures/golden/.work/backlog/idea-backlog.md +7 -0
  165. package/work-view/crates/cli/tests/fixtures/golden/.work/releases/v1.0/v1.0.md +16 -0
  166. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/CONVENTIONS.md +6 -0
  167. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/features/feat-dep-done.md +17 -0
  168. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/features/feat-design-ready.md +17 -0
  169. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/features/feat-impl-ready.md +17 -0
  170. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/stories/story-review-ready.md +17 -0
  171. package/work-view/crates/cli/tests/fixtures/with-malformed/.work/CONVENTIONS.md +4 -0
  172. package/work-view/crates/cli/tests/fixtures/with-malformed/.work/active/epics/malformed-no-closing-fence.md +8 -0
  173. package/work-view/crates/cli/tests/fixtures/with-malformed/.work/active/features/good-item.md +16 -0
  174. package/work-view/crates/cli/tests/integration.rs +2833 -0
  175. package/work-view/crates/core/Cargo.toml +13 -0
  176. package/work-view/crates/core/src/error.rs +61 -0
  177. package/work-view/crates/core/src/filter.rs +804 -0
  178. package/work-view/crates/core/src/graph.rs +324 -0
  179. package/work-view/crates/core/src/index.rs +590 -0
  180. package/work-view/crates/core/src/lib.rs +54 -0
  181. package/work-view/crates/core/src/model.rs +202 -0
  182. package/work-view/crates/core/src/parse.rs +494 -0
  183. package/work-view/crates/core/tests/fixtures/golden/.work/CONVENTIONS.md +15 -0
  184. package/work-view/crates/core/tests/fixtures/golden/.work/active/epics/epic-core.md +16 -0
  185. package/work-view/crates/core/tests/fixtures/golden/.work/active/features/feat-parser.md +16 -0
  186. package/work-view/crates/core/tests/fixtures/golden/.work/active/features/feat-query.md +16 -0
  187. package/work-view/crates/core/tests/fixtures/golden/.work/active/stories/malformed-no-id.md +15 -0
  188. package/work-view/crates/core/tests/fixtures/golden/.work/active/stories/story-parse-unit.md +16 -0
  189. package/work-view/crates/core/tests/fixtures/golden/.work/active/stories/story-security-gate.md +16 -0
  190. package/work-view/crates/core/tests/fixtures/golden/.work/archive/feat-old.md +16 -0
  191. package/work-view/crates/core/tests/fixtures/golden/.work/archive/feat-parser.md +17 -0
  192. package/work-view/crates/core/tests/fixtures/golden/.work/backlog/idea-future-board.md +7 -0
  193. package/work-view/crates/core/tests/fixtures/golden/.work/releases/v1.0/v1.0.md +16 -0
  194. package/work-view/crates/core/tests/fixtures/precedence/.work/CONVENTIONS.md +10 -0
  195. package/work-view/crates/core/tests/fixtures/precedence/.work/archive/dup-item.md +18 -0
  196. package/work-view/crates/core/tests/fixtures/precedence/.work/releases/v2.0/dup-item.md +18 -0
  197. package/work-view/crates/core/tests/integration.rs +541 -0
  198. package/work-view/dist/.gitattributes +1 -0
  199. package/work-view/dist/README.md +42 -0
  200. package/work-view/dist/aarch64-apple-darwin/work-view +0 -0
  201. package/work-view/dist/aarch64-unknown-linux-musl/work-view +0 -0
  202. package/work-view/dist/x86_64-apple-darwin/work-view +0 -0
  203. package/work-view/dist/x86_64-unknown-linux-musl/work-view +0 -0
@@ -0,0 +1,404 @@
1
+ ---
2
+ name: perf-scout
3
+ description: >
4
+ Cross-domain performance *idea* generator — a speculative brainstorm engine, not a profiler. Use
5
+ when the user asks for performance ideas, optimization angles, "how could this be faster", "what
6
+ would a game engine / database / GPU do here", a perf brainstorm, "ways to speed this up", or a
7
+ broad sweep of possible speedups. Fans parallel highest-thinking-model scouts across strategy lenses
8
+ (algorithmic, memory/locality, parallelism/SIMD, GPU, caching, I/O, distributed, game-engine,
9
+ database internals, compiler/runtime, approximation) through scanner agents, each surfacing *candidate* optimizations
10
+ borrowed from demanding domains as unvalidated hypotheses — never asserting gains are real. Then a
11
+ different model class (via peeragent, or a fresh max-effort sub-agent) prunes weak ideas and
12
+ surfaces missed angles. Writes a ranked report and parks ideas to .work/. Distinct from perf-design
13
+ (which measures and asserts — hand validated ideas there), bug-scan (correctness), and
14
+ refactor-design (structure).
15
+ ---
16
+
17
+ # Perf-Scout
18
+
19
+ You run a **cross-pollination idea engine** for performance. You take the
20
+ hardest-won strategies from the most demanding domains — AAA game engines,
21
+ database and storage internals, HPC, high-frequency trading, distributed
22
+ systems, GPU programming, compilers — and ask, for the code in front of you:
23
+ *could any of these apply here?*
24
+
25
+ You detect the stack and workload shape, choose relevant **strategy lenses**,
26
+ dispatch **one deep scanner/scout agent per lens in parallel** (each at the highest
27
+ thinking model available, using a generic sub-agent prompted with the scanner posture from `../principles/references/subagents.md`),
28
+ aggregate and rank the candidate ideas, then run the
29
+ whole deck past a **different model class** to prune the weak ideas and surface
30
+ the angles your first pass missed. The output is a ranked deck of *candidate*
31
+ optimizations and parked backlog ideas.
32
+
33
+ ## What this is — and what it is NOT
34
+
35
+ This skill **generates ideas**. It does not measure, profile, or prove anything.
36
+
37
+ - Every idea is a **hypothesis**: "borrowing X from how databases / game engines
38
+ / GPUs solve this, *this code might* go faster." You never assert a gain is
39
+ real — you can't, because you didn't measure it. Labelling ideas as speculative
40
+ is a feature, not a hedge: it's what makes a 40-idea brainstorm safe to read.
41
+ - Each idea carries a **validation path** — usually "hand to
42
+ `/agile-workflow:perf-design <id>` to actually profile and confirm." That skill
43
+ *measures and asserts*; this one *ideates and hypothesizes*. They're a pair.
44
+ - Distinct siblings: **perf-design** (profile, measure, assert, design the fix),
45
+ **bug-scan** (correctness bugs), **refactor-design** (structure/abstraction).
46
+ When the user wants *what to investigate*, that's you. When they want *what's
47
+ actually slow and proven*, that's perf-design.
48
+
49
+ Why speculation is worth shipping: the most valuable optimization is usually the
50
+ one you didn't think to consider. A different domain's playbook — a GPU's memory
51
+ coalescing, a game engine's entity-component layout, an LSM tree's write
52
+ batching — applied to an ordinary web service is exactly the angle a single mind
53
+ on a deadline never reaches for. This skill's job is to reach for all of them.
54
+
55
+ ## Highest-thinking-model mandate
56
+
57
+ Idea quality scales hard with model strength, and this skill deliberately trades
58
+ tokens for insight. Run **every** scanner/scout agent at maximum: use the host's strongest
59
+ read-only scout/reviewer setting, and use extra-high reasoning where the host
60
+ exposes it. Do not downgrade "simple" lenses. This does not replace the
61
+ peeragent cross-model pass: the peer reviewer still runs at the deepest effort
62
+ its agent supports (see Phase 5). Large deck reviews can take 10 to 30 minutes;
63
+ do not assume a quiet process has hung after only a few minutes.
64
+
65
+ If you ever feel tempted to save tokens by downgrading a model here, don't — that
66
+ trade is the opposite of what this skill is for.
67
+
68
+ ## Modes (standalone only)
69
+
70
+ There is no release-gate mode. Speculative ideas are not ship blockers; they're
71
+ investigation candidates. The path to action runs through perf-design or scope.
72
+
73
+ - `/agile-workflow:perf-scout` — scout the whole repo
74
+ - `/agile-workflow:perf-scout <path>` — scope to a directory or glob (`src/render/`, `**/*.rs`)
75
+ - `/agile-workflow:perf-scout <NL scope>` (e.g. "the request hot path", "the data ingest pipeline") — interpret against the codebase
76
+ - `/agile-workflow:perf-scout --lenses a,b,c` — restrict to named lenses (skip selection)
77
+ - `/agile-workflow:perf-scout --no-peer` — skip the cross-model pass (warn: it's the headline value)
78
+ - `/agile-workflow:perf-scout --park-all` — park every tier including long-shots (default parks only Investigate-first + Worth-a-look)
79
+ - `/agile-workflow:perf-scout --no-park` — write the report only, skip backlog parking
80
+
81
+ ## The strategy lenses (and their references)
82
+
83
+ Each scout loads exactly one of these — that's the progressive-disclosure move
84
+ that keeps each scout focused and your context lean. Each reference catalogs
85
+ ~10-15 strategies with the domain they're borrowed from, the code signals that
86
+ *suggest* (never prove) the strategy might apply, the speculative win, the
87
+ cost/risk, and how to validate.
88
+
89
+ | Lens | Reference | When to load |
90
+ |---|---|---|
91
+ | Algorithmic & data structures | [references/algorithmic-and-data-structures.md](references/algorithmic-and-data-structures.md) | Almost always. Loops, repeated work, nested iteration, sorting/searching, recomputation, growing collections. |
92
+ | Memory & data locality | [references/memory-and-data-locality.md](references/memory-and-data-locality.md) | CPU-bound hot paths, large object graphs, per-element processing, structs/arrays of records, pointer-heavy traversal. |
93
+ | Parallelism & vectorization | [references/parallelism-and-vectorization.md](references/parallelism-and-vectorization.md) | Independent work done sequentially, map/reduce shapes, numeric kernels, multi-core idle, large batch processing. |
94
+ | GPU & accelerators | [references/gpu-and-accelerators.md](references/gpu-and-accelerators.md) | Massively-parallel regular numeric work, large array/matrix/tensor math, image/signal processing, existing GPU/CUDA/Metal code, or compute-bound kernels that could move off the CPU. |
95
+ | Caching & memoization | [references/caching-and-memoization.md](references/caching-and-memoization.md) | Repeated identical computation/requests, expensive pure functions, hot read paths, derived values recomputed per call. |
96
+ | I/O & batching | [references/io-and-batching.md](references/io-and-batching.md) | DB/network/disk calls, per-item I/O in loops, serialization, syscalls, N+1 patterns, chatty service boundaries. |
97
+ | Distributed systems | [references/distributed-systems.md](references/distributed-systems.md) | Multi-node/service code, queues, RPC, replication, cross-region calls, coordination, fan-out/fan-in. |
98
+ | Game-engine & realtime | [references/game-engine-and-realtime.md](references/game-engine-and-realtime.md) | Per-frame/per-tick loops, simulations, spatial queries, entity collections, rendering, soft real-time budgets, allocation churn in a loop. |
99
+ | Database & storage internals | [references/database-and-storage-internals.md](references/database-and-storage-internals.md) | Custom storage/query/index code, in-memory stores, scans/filters/joins, write-heavy paths, on-disk formats. |
100
+ | Compiler, runtime & language | [references/compiler-runtime-and-language.md](references/compiler-runtime-and-language.md) | Hot inner loops, allocation/GC pressure, dynamic dispatch, boxing, interpreters, string building, reflection. |
101
+ | Approximation & precomputation | [references/approximation-and-precomputation.md](references/approximation-and-precomputation.md) | Exact answers where approximate would do, membership/cardinality/quantile queries, similarity search, expensive lookups computable ahead of time. |
102
+
103
+ ## Phase 1: Stack & shape discovery
104
+
105
+ Detect what you're scouting — structurally, with no profiling (you never measure
106
+ in this skill):
107
+
108
+ - **Languages & runtimes** — extensions, manifests (`package.json`, `Cargo.toml`,
109
+ `go.mod`, `pyproject.toml`, `pom.xml`, `*.csproj`, `CMakeLists.txt`).
110
+ - **Workload shape** — pick the dominant one(s); it steers lens relevance:
111
+ - *Request/response service* (HTTP/RPC handlers) → I/O, caching, distributed.
112
+ - *Batch / data pipeline* (ETL, jobs, stream processors) → algorithmic, parallelism, I/O, approximation.
113
+ - *Real-time / simulation / rendering / game loop* → game-engine, memory-locality, parallelism.
114
+ - *Library / CPU kernel / engine internals* (parsers, codecs, DB, compiler) → algorithmic, memory-locality, compiler/runtime, database-internals.
115
+ - **Hot-ish regions** — entry points and inner loops *likely* to dominate: API
116
+ routes, the main loop, per-request/per-event/per-frame code, nested loops,
117
+ serialization, query builders. You're guessing where the heat is, not
118
+ measuring it — say so.
119
+ - **Existing perf posture** — note any benchmarks, caches, pools, or SIMD already
120
+ present, so scouts don't re-propose what's already there.
121
+
122
+ Summarize the stack and shape in 5-7 lines. This summary goes into every scout
123
+ brief.
124
+
125
+ ## Phase 2: Lens selection
126
+
127
+ Map the detected stack and workload shape to the 11 lenses. Mark each **most
128
+ relevant**, **relevant**, or **skip**.
129
+
130
+ **structured question tool checkpoint** (multi-select): show the lenses with relevance
131
+ annotations. Recommend the most-relevant set for a focused scout, or all 11 for a
132
+ full cross-domain sweep. Default to all "most relevant" + "relevant" if the user
133
+ doesn't pick. If invoked with `--lenses a,b,c`, skip the prompt and use exactly
134
+ those.
135
+
136
+ Run at least 4 lenses — fewer than that defeats the cross-pollination purpose.
137
+ Always include `algorithmic-and-data-structures` unless explicitly excluded; it's
138
+ relevant to nearly all code.
139
+
140
+ ## Phase 3: Fan-out idea generation
141
+
142
+ For each selected lens, spawn **one parallel scanner/scout agent in a single message**
143
+ so they run concurrently. Use a generic sub-agent prompted with the scanner posture from `../principles/references/subagents.md`,
144
+ the host's generic/general-purpose subagent prompted with the scanner/scout
145
+ posture from `../principles/references/subagents.md`, and extra-high reasoning
146
+ when available; otherwise use the same-host read-only ideation fallback.
147
+
148
+ ### Scope (passed into every scout)
149
+
150
+ Resolve the scope to a concrete file list with `git ls-files` (plus the path
151
+ filter or NL interpretation, if any). Cap absurd scopes: if the repo is huge,
152
+ focus scouts on the hot-ish regions from Phase 1 and say so in the report.
153
+
154
+ ### Scout brief template
155
+
156
+ Each scout gets this brief. Read it carefully — the framing (hypotheses, not
157
+ findings; borrowed-from attribution; validation path) is what makes the output
158
+ honest:
159
+
160
+ > You are a **perf-scout scanner agent** for the **<lens>** lens. Follow the
161
+ > agile-workflow scanner contract: source-read-only, no fixes, no recursive
162
+ > sub-agents. Your job is to
163
+ > generate *candidate* performance ideas — speculative hypotheses, not proven
164
+ > wins. You do not measure or profile. You surface angles worth investigating.
165
+ >
166
+ > **Reference (load FIRST)**: `<absolute path to references/<lens>.md>`
167
+ > Read the whole file. It is your catalog of strategies, where each is borrowed
168
+ > from, and the code signals that *suggest* it might apply.
169
+ >
170
+ > **Scope** — consider ONLY these files:
171
+ > ```
172
+ > <file list>
173
+ > ```
174
+ >
175
+ > **Stack & workload shape** (from orchestrator):
176
+ > ```
177
+ > <stack summary from Phase 1>
178
+ > ```
179
+ >
180
+ > **Already present** (don't re-propose what exists): `<caches/pools/SIMD/etc., or "none noted">`
181
+ >
182
+ > **Method**:
183
+ > 1. Load the lens reference. Internalize its strategies and detection signals.
184
+ > 2. Web-search 1-3 times for current, domain-specific techniques for THIS stack
185
+ > and workload (e.g. "data-oriented design ECS cache locality 2025", "io_uring
186
+ > batching Rust", "DuckDB vectorized execution technique"). Bring in strong
187
+ > ideas from the literature even if not in the reference — attribute them.
188
+ > 3. Read the in-scope code through this lens. For each place the lens *could*
189
+ > apply, form a candidate idea. Prefer high-leverage, non-obvious angles
190
+ > borrowed from a demanding domain over generic "add a cache" advice.
191
+ > 4. For each candidate idea, record the fields below. Be concrete about WHERE
192
+ > (cite `file:line` or `file:function`) and WHAT (the specific transform).
193
+ > 5. Be honest about applicability. An idea you're only 30% sure fits is still
194
+ > worth surfacing — just mark it **Speculative**. Do NOT fabricate file
195
+ > locations; if an idea is general ("the whole ingest path could be batched"),
196
+ > cite the representative site.
197
+ >
198
+ > **Per-idea fields**:
199
+ > - **Title** (one line — the idea, not the problem)
200
+ > - **Strategy** (named strategy from the reference, or "new" with a one-line source)
201
+ > - **Borrowed from** (the domain this technique comes from — game engines, LSM trees, GPU, HFT, etc.)
202
+ > - **Location** (`file:line` or `file:function` — the representative site)
203
+ > - **The idea** (2-4 sentences: the specific transform you'd try here)
204
+ > - **Why it might help** (the speculative mechanism — *might*, never *will*)
205
+ > - **Leverage / Applicability / Cost** (see the ranking rubric — High/Med/Low each)
206
+ > - **Validate by** (how to confirm it's real: the metric to measure, the benchmark to write, "profile via perf-design")
207
+ > - **Risk** (correctness, complexity, memory, or behavior-change concerns — one line)
208
+ >
209
+ > **Rules**:
210
+ > - These are hypotheses. Never claim a speedup is real or guaranteed. Use
211
+ > "might", "could", "is a candidate for".
212
+ > - Cite a representative `file:line`/`function` for every idea.
213
+ > - Don't propose what already exists (see "Already present").
214
+ > - Quality over quantity: 5 sharp, non-obvious, well-located ideas beat 25
215
+ > generic ones. Aim for the ideas a specialist from that domain would spot.
216
+ > - Empty is valid: if a lens genuinely doesn't apply to this code, say so.
217
+ > - Don't implement anything. Ideas only.
218
+ >
219
+ > **Output** — a single markdown doc:
220
+ > ```
221
+ > ## Lens: <name>
222
+ > ## Applies here?: <one-line — strongly / partially / barely, and why>
223
+ > ## Candidate ideas
224
+ >
225
+ > ### Idea 1
226
+ > - **Title**: ...
227
+ > - **Strategy**: ...
228
+ > - **Borrowed from**: ...
229
+ > - **Location**: `file:line`
230
+ > - **The idea**: ...
231
+ > - **Why it might help**: ...
232
+ > - **Leverage**: High|Med|Low · **Applicability**: Likely|Plausible|Speculative · **Cost**: Low|Med|High
233
+ > - **Validate by**: ...
234
+ > - **Risk**: ...
235
+ > ```
236
+ > Followed by:
237
+ > ```
238
+ > ## Summary
239
+ > - Files considered: <n>
240
+ > - Strategies applied: <list>
241
+ > - Ideas: High-leverage=<n>, Medium=<n>, Low=<n>
242
+ > ```
243
+
244
+ ### Wave coordination
245
+
246
+ - Dispatch all selected scouts in a **single message** (parallel).
247
+ - If a scout errors, record it as a gap in the report — don't blindly re-run.
248
+ - If a scout returns >20 ideas, ask it (via follow-up message) to keep the top 15 by
249
+ Leverage × Applicability. A flood usually means generic pattern-matching rather
250
+ than the sharp domain-borrowed ideas you want.
251
+
252
+ ## Phase 4: Aggregate, dedupe, cluster, rank
253
+
254
+ Collect every scout's ideas, then:
255
+
256
+ 1. **Dedupe** — same `file:line` + same essential transform across two lenses →
257
+ keep one, note "also surfaced by: <lens>". Two *different* transforms at the
258
+ same site are two ideas; keep both.
259
+ 2. **Cluster** — group by file/subsystem. A subsystem with many ideas may deserve
260
+ a single "rethink this layer's data model" idea rather than ten micro-ideas.
261
+ 3. **Rank** — score each idea with the rubric in
262
+ [references/idea-ranking.md](references/idea-ranking.md): a **Priority tier**
263
+ (Investigate-first / Worth-a-look / Long-shot) from Leverage × Applicability
264
+ vs. Cost × Risk. Read that reference; don't invent your own scale.
265
+ 4. **Score each lens 0-10** for *opportunity density* — how much plausible,
266
+ high-leverage headroom this lens found (see the ranking reference). This is an
267
+ opportunity signal, NOT a quality grade of the code.
268
+
269
+ ## Phase 5: Cross-model peer pass (the headline)
270
+
271
+ A different model has different blind spots. The whole point of this pass is to
272
+ catch the ideas your scouts collectively missed and prune the ones that don't
273
+ hold up — exactly what a fresh, differently-trained mind is good at. Run it by
274
+ default; only skip on `--no-peer` (and warn that you're skipping the best part).
275
+
276
+ Read **[references/peer-review-pass.md](references/peer-review-pass.md)** for the
277
+ full mechanics. In brief:
278
+
279
+ 1. **Pick the reviewer.** Prefer a **different model class** via peeragent
280
+ (resolve the wrapper from the peeragent plugin location — never assume it's on
281
+ PATH) to maximize blind-spot diversity — pick the concrete target from the
282
+ host→peer pairing in [../principles/references/models.md](../principles/references/models.md)
283
+ (Claude host → codex/gemini/zai; Codex host → claude opus/gemini/zai; etc.).
284
+ Same-class peers add little; in that case use the fallback. A top-tier reasoning
285
+ peer may take 10 to 30 minutes for a large deck review; no return after a few
286
+ minutes is not a hang. This pass is the **adversarial** phase; for a deep or
287
+ complex deck, precede it with a **completeness/advisory** pass from a *second*
288
+ different class if available (see the two-phase ordering in
289
+ [../principles/references/models.md](../principles/references/models.md) §6).
290
+ 2. **Fallback** when peeragent is unavailable, fails, or would be same-class:
291
+ spawn a **fresh max-effort reviewer sub-agent** when available that sees only
292
+ the codebase, the lens catalog, and the idea deck — NOT your scouts'
293
+ reasoning — so it reviews with independent context. This is the "max compute
294
+ and quality subagent" fallback.
295
+ 3. **Ask the reviewer for three things** (write the deck to a temp file, pass via
296
+ `--prompt-file`): (a) which ideas are weak, implausible, or wrong, and why;
297
+ (b) **gaps** — high-leverage angles, strategies, or whole lenses the deck
298
+ missed; (c) new candidate ideas in the same hypothesis framing. Include the
299
+ no-recursion instruction. Don't lead the reviewer toward your conclusions.
300
+ 4. **Integrate honestly.** Prune ideas you agree are weak (note them as "pruned by
301
+ peer: <reason>" — don't silently delete). Add gap ideas, attributed
302
+ `source: peer-<agent>`. If the peer names a missed *lens*, you may fan out one
303
+ more scout (Phase 3) for it, then re-rank.
304
+ 5. **One pass is usually enough** — idea generation isn't a converging artifact
305
+ the way a design doc is. Loop a second time only if the peer opened a whole new
306
+ high-value direction.
307
+
308
+ Record what the peer pruned and added; it goes in the report so the user sees the
309
+ cross-model value.
310
+
311
+ ## Phase 6: Output
312
+
313
+ Two outputs: a ranked report AND parked backlog ideas (unless `--no-park`).
314
+
315
+ ### 6a. Park ideas to backlog (default)
316
+
317
+ Skip entirely on `--no-park`. Otherwise:
318
+
319
+ 1. **Verify substrate.** If `.work/CONVENTIONS.md` is missing, the project isn't
320
+ on agile-workflow — skip parking, note it in the report, and tell the user to
321
+ run `/agile-workflow:convert` if they want substrate tracking. (The report is
322
+ still the primary deliverable; parking degrades gracefully.)
323
+ 2. **Choose which ideas to park.** By default, park only **Investigate-first** and
324
+ **Worth-a-look** ideas — these are the candidates someone might actually action.
325
+ Long-shots stay in the report only, so the backlog doesn't fill with speculative
326
+ noise. Pass `--park-all` to park every tier including long-shots. The report
327
+ always lists all tiers regardless.
328
+ 3. **Build the existing-ideas index** for idempotency. The canonical dedupe key is
329
+ (`idea_location`, `idea_lens`) — the same key used everywhere in this skill:
330
+ ```bash
331
+ mkdir -p /tmp; : > /tmp/perfscout-existing.txt
332
+ for f in .work/backlog/perf-scout-*.md; do
333
+ [ -f "$f" ] || continue
334
+ grep -q '^idea_origin: scout$' "$f" || continue
335
+ loc=$(grep -m1 '^idea_location:' "$f" | awk '{print $2}')
336
+ lens=$(grep -m1 '^idea_lens:' "$f" | awk '{print $2}')
337
+ [ -n "$loc" ] && echo "$loc $lens $f" >> /tmp/perfscout-existing.txt
338
+ done
339
+ ```
340
+ 4. **Park each selected idea** as `.work/backlog/perf-scout-<slug>.md` using
341
+ [references/parked-item-template.md](references/parked-item-template.md). Skip
342
+ any idea whose (`file:line`, `idea_lens`) pair already appears in the index;
343
+ tally "duplicates skipped". On slug collision, suffix `-2`, `-3`. **Record the
344
+ exact path of every file you create** — you'll stage those explicitly next.
345
+ 5. **Commit** the newly-created files in one commit. Stage only the paths you
346
+ created this run (never a `perf-scout-*.md` glob — that can sweep pre-existing
347
+ or unrelated edits; never `git add -A`):
348
+ ```bash
349
+ git add <each new file path created this run>
350
+ git commit -m "perf-scout: park <N> ideas (<scope>)"
351
+ ```
352
+
353
+ ### 6b. Write the report
354
+
355
+ Write `perf-scout-report.md` at repo root using
356
+ [references/report-template.md](references/report-template.md). Include: the
357
+ stack & shape profile, the per-lens opportunity-density table, ideas grouped by
358
+ **Priority tier** (each with borrowed-from, location, validation path, and parked
359
+ id), a "Top 5 to investigate first" callout, the cross-model peer summary
360
+ (pruned + added), lenses skipped + why, and the parking summary.
361
+
362
+ ### 6c. Summarize to the user
363
+
364
+ - The stack & workload shape you scouted.
365
+ - Idea counts by Priority tier (Investigate-first / Worth-a-look / Long-shot).
366
+ - The **Top 5 to investigate first**, one line each with `file:line` and the
367
+ domain each is borrowed from.
368
+ - What the cross-model peer pass pruned and added (the headline value).
369
+ - Path to the report; parked count + duplicates skipped (or why parking was skipped).
370
+ - A reminder that **every idea is an unvalidated hypothesis** — nothing here is a
371
+ measured win yet.
372
+ - **structured question tool** (next steps):
373
+ - "Hand the top idea(s) to `/agile-workflow:perf-design` to profile and validate"
374
+ - "Promote a tier into tracked work via `/agile-workflow:scope`"
375
+ - "Dive deeper into one lens (re-scout with `--lenses <lens>`)"
376
+ - "Done for now — leave the parked ideas in backlog"
377
+
378
+ ## Guardrails
379
+
380
+ - **Never assert a gain is real.** You didn't measure it. Every idea is a
381
+ hypothesis with a validation path. This is the load-bearing rule — the skill is
382
+ only safe to use *because* it's honest about being speculative.
383
+ - **Always attribute borrowed-from.** The cross-domain provenance is the value;
384
+ "this is how a game engine / LSM tree / GPU does it" is what makes an idea worth
385
+ reading. An idea with no source domain is probably a generic one — sharpen it.
386
+ - **Every idea has a validation path.** If you can't say how to confirm it, you
387
+ haven't thought it through. Usually: hand to perf-design.
388
+ - **The ideation happens in the scanner/scout agents, not here.** Your job is discovery,
389
+ dispatch, aggregation, the peer pass, and the report. Don't re-derive a scout's
390
+ work in the orchestrator — that throws away the progressive-disclosure win.
391
+ - **Always fan out, always at max model.** One scout per lens, parallel, Opus /
392
+ xhigh. Never serialize, never downgrade.
393
+ - **Run the peer pass by default.** A different model class is the single best
394
+ source of the angles you missed. Skipping it (`--no-peer`) should feel like a
395
+ loss, and you should say so.
396
+ - **Quality over quantity.** A deck of 12 sharp, well-located, domain-borrowed
397
+ hypotheses beats 60 generic "add a cache / parallelize it" lines. Prune
398
+ aggressively in Phase 4 and let the peer prune more.
399
+ - **Don't measure, don't profile, don't fix.** Measurement is perf-design.
400
+ Fixing is implement. This skill stops at ranked, parked ideas.
401
+ - **Respect scope.** If the user gave a path or NL scope, don't expand past it.
402
+ - **Idempotent re-runs.** Index existing `perf-scout-*` backlog ideas before
403
+ parking; skip ideas already captured at the same (`file:line`, `idea_lens`) —
404
+ the one canonical dedupe key, used here and in the parked-item template.
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Perf Scout"
3
+ short_description: "Use Perf Scout for repo workflows"
4
+ default_prompt: "Use $perf-scout for this repository."
5
+ policy:
6
+ allow_implicit_invocation: false
@@ -0,0 +1,126 @@
1
+ # Algorithmic & Data Structures — Perf-Scout Strategy Lens
2
+
3
+ > **When to load this lens**: almost always. Any code with loops, repeated work,
4
+ > nested iteration, searching/sorting, recomputation, or growing collections.
5
+ >
6
+ > **Where these ideas come from**: classical algorithms, competitive programming,
7
+ > database query planners, and the "do less work" school of optimization. The
8
+ > highest-leverage wins almost always live here — a better complexity class beats
9
+ > any micro-optimization. Every entry is a *candidate* hypothesis, not a proven
10
+ > win. Cite a representative `file:line`, attribute the source, give a validation
11
+ > path.
12
+
13
+ ## Detection signals (where this lens might apply — not proof)
14
+ - Nested loops over the same or related collections (`for ... for ...`), especially O(n²) shapes.
15
+ - Linear scans to find/membership-test (`.find`, `.filter(...)[0]`, `in list`, `indexOf`) inside a loop.
16
+ - Repeated identical computation across iterations or calls with the same inputs.
17
+ - Sorting inside a loop, or re-sorting data that's already mostly ordered.
18
+ - Building strings/collections by repeated concatenation or append-with-grow.
19
+ - Recomputing aggregates (sum, max, count) from scratch after small mutations.
20
+ - Recursion with overlapping subproblems; full recomputation on each call.
21
+
22
+ ## Strategies
23
+
24
+ ### 1. Lower the complexity class
25
+ - **Borrowed from**: algorithm design fundamentals.
26
+ - **The idea**: replace an O(n²) (or worse) shape with O(n log n) or O(n) by choosing a structure that answers the inner question in O(1)/O(log n) — hash set/map for membership, sorted array + binary search, heap for top-k.
27
+ - **Code signals**: a linear `find`/`includes`/`in` inside a loop; double loops comparing all pairs.
28
+ - **Speculative win**: superlinear-to-linear collapse; the only kind of win that *grows* with input size.
29
+ - **Cost / risk**: extra memory for the index; index build cost must amortize over enough queries.
30
+ - **Validate by**: benchmark across input sizes to confirm the slope changed, not just the constant — hand to perf-design.
31
+
32
+ ### 2. Precompute / build an index once
33
+ - **Borrowed from**: database indexing.
34
+ - **The idea**: pay once to build a lookup structure (map, sorted index, prefix-sum array, inverted index) so each later query is cheap, instead of scanning every time.
35
+ - **Code signals**: the same collection scanned repeatedly with different keys; range/aggregate queries recomputed.
36
+ - **Speculative win**: turns N scans into 1 build + N cheap lookups.
37
+ - **Cost / risk**: staleness if the source mutates; memory; only wins when queries ≫ rebuilds.
38
+ - **Validate by**: count actual query-to-rebuild ratio; benchmark build + query vs. scan.
39
+
40
+ ### 3. Memoize / cache pure computation
41
+ - **Borrowed from**: dynamic programming, functional programming.
42
+ - **The idea**: cache results of expensive pure functions keyed by arguments; reuse on repeat calls.
43
+ - **Code signals**: a deterministic function called repeatedly with a small set of distinct inputs.
44
+ - **Speculative win**: collapses repeated work to one computation per distinct input.
45
+ - **Cost / risk**: unbounded cache growth; correctness if inputs aren't truly the full key. (Caching lens covers eviction.)
46
+ - **Validate by**: measure hit rate on real input distribution.
47
+
48
+ ### 4. Incrementalize instead of recompute
49
+ - **Borrowed from**: incremental computation, spreadsheet engines, React reconciliation.
50
+ - **The idea**: maintain a result as inputs change (delta update) rather than recomputing from scratch — running sums, dirty-flag recompute, diff-and-patch.
51
+ - **Code signals**: full recompute of an aggregate/derived structure after a small mutation; "recalculate everything" on any change.
52
+ - **Speculative win**: O(change) instead of O(total) per update.
53
+ - **Cost / risk**: incremental logic is subtler and easier to get wrong than full recompute.
54
+ - **Validate by**: benchmark with realistic mutation/read ratios; property-test incremental == full.
55
+
56
+ ### 5. Amortize with the right growable structure
57
+ - **Borrowed from**: amortized analysis, dynamic arrays.
58
+ - **The idea**: replace repeated O(n) reallocation/shift with an amortized-O(1) structure — pre-sized buffers, ring buffers, deques, gap buffers, string builders.
59
+ - **Code signals**: `array.shift()`/insert-at-front in a loop, string `+=` in a loop, list grown one element at a time without reserve.
60
+ - **Speculative win**: removes a hidden O(n²) from naive concatenation/insertion.
61
+ - **Cost / risk**: minimal; mostly an API swap.
62
+ - **Validate by**: benchmark on large inputs where the quadratic bites.
63
+
64
+ ### 6. Pick a structure that matches the access pattern
65
+ - **Borrowed from**: data-structure theory.
66
+ - **The idea**: match structure to dominant operation — heap for top-k/priority, balanced tree / skip list for ordered range queries, trie for prefix matching, union-find for connectivity, segment/Fenwick tree for range aggregates, bitset for dense membership.
67
+ - **Code signals**: sorting just to take the top few; repeated range/prefix/aggregate queries done by scan.
68
+ - **Speculative win**: each query drops from O(n) to O(log n) or O(1).
69
+ - **Cost / risk**: more code; structure must fit the real query mix.
70
+ - **Validate by**: enumerate the real operation mix; benchmark the candidate structure.
71
+
72
+ ### 7. SIMD-probed open-addressing hash table
73
+ - **Borrowed from**: Google Abseil Swiss tables and Facebook folly F14 (`abseil.io/about/design/swisstables`, `facebook/folly` F14.md).
74
+ - **The idea**: when a hot hash map is the bottleneck, a Swiss/F14-style table stores tiny per-slot control bytes contiguously and scans a 16- or 14-slot group with a single SIMD instruction, so most lookups skip key comparisons and tolerate ~87% (Swiss) / 12-of-14 (F14) load factors with short probe chains.
75
+ - **Code signals**: a profile dominated by `std::unordered_map`/chaining-map lookups or rehash churn; pointer-chasing per probe; high-frequency point lookups on a large map.
76
+ - **Speculative win**: lookups might drop several-fold and memory shrink versus a node-based chaining map, because the SIMD group scan replaces per-node comparisons and indirection.
77
+ - **Cost / risk**: open addressing perturbs iteration order and reference stability; pathological hashes still degrade; only matters if map ops actually dominate the profile.
78
+ - **Validate by**: swap in the candidate map (e.g. `absl::flat_hash_map`, `folly::F14`) behind the same interface and A/B the hot path; profile via perf-design.
79
+
80
+ ### 8. Cache-friendly ordered index (adaptive radix tree)
81
+ - **Borrowed from**: the Adaptive Radix Tree (ART) in the HyPer main-memory DB (Leis et al., ICDE 2013, `db.in.tum.de/~leis/papers/ART.pdf`).
82
+ - **The idea**: when you need *ordered* lookups plus range scans, an adaptive radix tree sizes each node (4/16/48/256 children) to its actual fanout and uses path compression, giving trie-style O(key-length) lookups with far less space and pointer-chasing than a balanced BST — and unlike a hash map it preserves order for range queries.
83
+ - **Code signals**: a balanced BST / red-black map on the hot path for ordered or prefix/range access; a sorted array re-bisected on every query with frequent inserts; sort-then-range patterns.
84
+ - **Speculative win**: lookups might approach hash-map speed while keeping order; the HyPer paper measured ART near 2x a tuned hash-table/red-black combo on its workload — treat that as a candidate, not a promise.
85
+ - **Cost / risk**: implementation complexity; wins are key-distribution-dependent; a plain hash map still beats it when order is never needed.
86
+ - **Validate by**: benchmark ART (e.g. an `art`/`ART`-style library) against the current ordered structure on the real key set and query mix; profile via perf-design.
87
+
88
+ ### 9. Compressed bitmap for set-heavy membership and intersection
89
+ - **Borrowed from**: Roaring bitmaps, used in Apache Lucene, Druid, Spark, ClickHouse, Pinot (`roaringbitmap.org`, "Better bitmap performance with Roaring", arXiv:1402.6407).
90
+ - **The idea**: represent large integer-ID sets as a Roaring bitmap (per-64K-chunk array/bitmap/run containers) so AND/OR/ANDNOT run as native word-parallel bitwise ops, replacing per-element hash-set loops or list intersections — fast on dense sets, compact on sparse ones, no manual tuning.
91
+ - **Code signals**: filtering/joining by intersecting large ID sets via nested loops or `HashSet.retainAll`; postings-list / tag / permission / candidate-row set algebra; many `contains` checks over dense integer keys.
92
+ - **Speculative win**: intersections might run multiple-fold faster and far smaller than hash-set or sorted-list approaches, since whole 64-bit words are combined at once instead of element-by-element.
93
+ - **Cost / risk**: only fits integer-keyed (or dictionary-encoded) sets; serialization/format lock-in; no benefit on tiny sets.
94
+ - **Validate by**: model real IDs as roaring bitmaps and benchmark the set-op hot path vs. the current approach at production cardinalities; profile via perf-design.
95
+
96
+ ### 10. Reformulate the problem
97
+ - **Borrowed from**: math/algorithmic insight, query optimization.
98
+ - **The idea**: change *what* you compute — process in a different order, transform to a cheaper equivalent (e.g. sort-then-scan instead of all-pairs, two-pointer instead of nested loop, prefix sums instead of repeated range sums, bucket/counting sort when keys are bounded).
99
+ - **Code signals**: brute-force all-pairs; "for each X, search all Y"; repeated overlapping range work.
100
+ - **Speculative win**: often the biggest single jump — a different formulation can erase a whole loop.
101
+ - **Cost / risk**: requires understanding the problem, not just the code; highest insight cost.
102
+ - **Validate by**: prove equivalence on the domain; benchmark.
103
+
104
+ ### 11. Short-circuit and prune
105
+ - **Borrowed from**: search algorithms (alpha-beta, branch-and-bound).
106
+ - **The idea**: exit early, prune branches that can't matter, order checks cheapest-first / most-discriminating-first, bound the search.
107
+ - **Code signals**: full scans that could stop at first match; expensive predicate evaluated before a cheap one; computing all results when only existence/first/any is used.
108
+ - **Speculative win**: average-case savings, sometimes large, with no structural change.
109
+ - **Cost / risk**: low; watch correctness of the early-exit condition.
110
+ - **Validate by**: benchmark on representative (not worst-case) inputs.
111
+
112
+ ### 12. Batch the work, not the items
113
+ - **Borrowed from**: vectorized databases, BLAS.
114
+ - **The idea**: process many items per operation instead of one-at-a-time — group, sort-and-merge, do set operations once over the whole collection rather than per element.
115
+ - **Code signals**: per-element work that re-derives shared context each time; one-row-at-a-time processing of a bulk dataset.
116
+ - **Speculative win**: amortizes fixed per-call overhead across the batch.
117
+ - **Cost / risk**: larger working set; latency vs. throughput tradeoff.
118
+ - **Validate by**: benchmark batch vs. per-item at realistic sizes.
119
+
120
+ ### 13. Use cheaper exactness (lazy / streaming)
121
+ - **Borrowed from**: lazy evaluation, streaming/iterator pipelines.
122
+ - **The idea**: avoid materializing intermediate collections; stream through transforms; compute only what's consumed (take-n, first, any).
123
+ - **Code signals**: `map().filter().slice(0,k)` materializing the whole list before slicing; building a big intermediate to use a fraction.
124
+ - **Speculative win**: avoids work for unconsumed elements; lower peak memory.
125
+ - **Cost / risk**: laziness can obscure cost and complicate debugging.
126
+ - **Validate by**: measure how much of the intermediate is actually consumed; benchmark.