Skip to content

perf: reduce context duplication in WebPerf skills (-16.6% lines)#67

Merged
nucliweb merged 9 commits intomainfrom
perf/reduce-skill-context-duplication
Mar 17, 2026
Merged

perf: reduce context duplication in WebPerf skills (-16.6% lines)#67
nucliweb merged 9 commits intomainfrom
perf/reduce-skill-context-duplication

Conversation

@nucliweb
Copy link
Owner

Summary

WebPerf skills contained redundant information — the same content appeared in multiple places within each SKILL.md, consuming unnecessary context tokens without adding value. This PR removes those duplications while preserving all actionable information.

Net result: 1,368 → 1,141 lines across all SKILL.md files (-227 lines, -16.6%), without losing any information that wasn't already covered by the Decision Tree.

What was duplicated and how it was fixed

generate-skills.js — structural fixes (affects all skills)

Issue Fix
references/snippets.md pointer appeared twice per skill (inline after script list + in ## References) Removed inline copy
Execution instructions (mcp__chrome-devtools__evaluate_script) appeared in intro paragraph AND as a footer Removed footer
Meta-skill had two tables expressing the same data: ## Skills by Category and ## Quick Reference Merged into single ## Quick Reference table with columns Skill | Snippets | Trigger phrases

WORKFLOWS.md sources — per-category

Interaction (-33 lines in SKILL.md, -12.2%)

  • Removed ### Cross-Skill Triggers — all triggers already present inline in the Decision Tree
  • Preserved unique trigger: webperf-core-web-vitals:INP.js moved inline to After Interactions.js DT node

Loading (-12 lines in SKILL.md, -5.3%)

  • Removed ### Image Loading Audit — image queries route through webperf-media, which already cross-references these loading scripts in its own workflows

Media (-75 lines in SKILL.md, -25.7%)

  • Removed ### Cross-Skill Triggers — every trigger mapped 1:1 to an existing DT node
  • Removed ### Common Issues and Resolutions — each "issue" was a prose rewrite of a DT node (e.g. "LCP slow + image" = After Image-Element-Audit.js → LCP lacks fetchpriority)
  • Preserved unique trigger: "images competing with critical resources → Find-render-blocking-resources.js + TTFB-Resources.js" moved inline to After Image-Element-Audit.js

Resources (-90 lines in SKILL.md, -31.3%)

  • Removed ### Cross-Skill Triggers — duplicated DT nodes verbatim
  • Removed ### Real-World Scenarios — four scenarios were narrative rewrites of DT nodes (e.g. "User on 3G" = the effectiveType: "3g" node as a story)
  • Removed ### Testing Adaptive Loading — described a manual Chrome DevTools workflow, not executable via MCP, referenced no skill scripts
  • Reformatted ### Adaptive Loading Implementation Guide from fenced javascript blocks (containing plain text strategies, not executable code) to bullet lists — same content, ~8 fewer lines
  • Preserved unique triggers: TTFB-Sub-Parts.js + Service-Worker-Analysis.js added to RTT > 300ms DT node; LCP.js + INP.js added to 2g and 3g DT nodes

Impact by skill

Skill Before After Removed Reduction
webperf-core-web-vitals 238 235 -3 -1.3%
webperf-interaction 271 238 -33 -12.2%
webperf-loading 228 216 -12 -5.3%
webperf-media 292 217 -75 -25.7%
webperf-resources 288 198 -90 -31.3%
webperf (meta) 51 37 -14 -27.5%
Total 1,368 1,141 -227 -16.6%

Design principle

The fix applies a single source of truth rule: the Decision Tree is the authoritative place for "what to do next" logic. Supporting sections (Cross-Skill Triggers, Common Issues, Real-World Scenarios) that summarize or restate DT nodes are redundant by definition. Where those sections contained genuinely unique information not already in the DT, it was moved inline before removing the section.

Test plan

  • node scripts/generate-skills.js runs without errors
  • All 5 category skills + meta-skill generated successfully
  • Skills copied to .claude/skills/ correctly
  • No Cross-Skill Triggers, Common Issues, Real-World Scenarios, or Testing Adaptive Loading sections in generated SKILL.md files
  • references/snippets.md pointer appears exactly once per skill (in ## References)
  • Unique cross-skill triggers preserved inline in Decision Tree nodes

Bugs fixed:
- LCP-Video-Candidate: apply activationStart correction in both non-video
  and video return paths (bfcache navigations were returning wrong values)
- LCP + LCP-Trail: use getComputedStyle for background-image detection
  instead of el.style, which only reads inline styles
- CLS: add message and getDataFn to synchronous return so agents know
  they can call getCLS() after interactions for an updated value
- INP: remove misleading rating: "good" from getINP() error case when no
  interactions recorded; add getDataFn: "getINP" so agents can retry

Inconsistencies resolved:
- LCP-Sub-Parts: align internal SUB_PARTS keys with schema output keys
  (loadDelay → resourceLoadDelay, loadTime → resourceLoadTime, etc.)
- LCP-Sub-Parts + LCP-Trail: preserve hostname in URL for cross-origin
  resources (cdn.example.com/…/hero.jpg instead of just hero.jpg)
- LCP-Image-Entropy: add LCP element highlighting, consistent with all
  other LCP scripts

SKILL.md / schema improvements:
- WORKFLOWS: add Error Recovery section to decision tree
- WORKFLOWS: mark cross-skill scripts not yet available as (pending)
- WORKFLOWS: clarify cross-skill triggers require reporting to parent
  agent (context: fork — subagent cannot invoke other skills directly)
- WORKFLOWS: document getINPDetails() usage in INP debugging workflow
- SCHEMA: update CLS schema to include message and getDataFn fields
- SCHEMA: document getINPDetails() return shape and when to use it
Remove redundant sections from WORKFLOWS.md sources and the skill
generator that duplicated information already present in Decision Trees.

Changes in generate-skills.js:
- Remove inline `references/snippets.md` pointer after script list
  (already listed in ## References section)
- Remove duplicate execution footer (already in intro paragraph)
- Merge "Skills by Category" and "Quick Reference" tables in meta-skill
  into a single "Quick Reference" table (Skill | Snippets | Trigger phrases)

Changes in WORKFLOWS.md sources:
- Interaction: remove ### Cross-Skill Triggers (30 lines); preserve
  unique webperf-core-web-vitals:INP.js trigger inline in Decision Tree
- Loading: remove ### Image Loading Audit (9 lines); image queries route
  through webperf-media which already cross-references these scripts
- Media: remove ### Cross-Skill Triggers (38 lines) and
  ### Common Issues and Resolutions (38 lines); both were 1:1 summaries
  of the Decision Tree; unique trigger (images competing with critical
  resources) moved inline to After Image-Element-Audit.js node
- Resources: remove ### Cross-Skill Triggers (29 lines),
  ### Real-World Scenarios (25 lines), and ### Testing Adaptive Loading
  (18 lines); unique triggers (TTFB-Sub-Parts, Service-Worker-Analysis
  for high RTT; LCP.js/INP.js for slow connections) moved inline to DT;
  reformat ### Adaptive Loading Implementation Guide from fenced
  javascript blocks to bullet lists (-8 lines)

No actionable information lost: every removed item was already covered
by an inline Decision Tree node or has been incorporated into one.

SKILL.md line counts (before → after):
  webperf-core-web-vitals  238 → 235  (-1.3%)
  webperf-interaction      271 → 238  (-12.2%)
  webperf-loading          228 → 216  (-5.3%)
  webperf-media            292 → 217  (-25.7%)
  webperf-resources        288 → 198  (-31.3%)
  webperf (meta)            51 →  37  (-27.5%)
  total                   1368 → 1141 (-16.6%, -227 lines)
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webperf-snippets Ready Ready Preview, Comment Mar 17, 2026 11:16pm
webperf-snippets-u6am Ready Ready Preview, Comment Mar 17, 2026 11:16pm

Add buildReadableScript() to generate-skills.js, producing a
skills/{category}/scripts-readable/ directory alongside the existing
minified scripts/ output.

Readable scripts are intended for contribution to external repos (e.g.
chrome-devtools-mcp) where minified code is not appropriate. They differ
from the minified build in three ways:
- No header comment (file path / sha256 / GitHub URL)
- No console.* output code (removed via Terser drop_console)
- Readable formatting (beautify, 2-space indent, mangle disabled)

Terser options used: defaults:false to suppress all transforms except
drop_console + unused DCE + dead_code removal. Post-processing restores
number literals shortened by the output generator (1e4 → 10000, .1 → 0.1)
and removes void 0 placeholders left by drop_console.

Note: display-only infrastructure (RATING constants, logXxx helpers) that
served only console output remains as inert stubs after console removal.
The scripts are functionally correct — stubs execute but have no effect.
scripts-readable/ was generated inside skills/{category}/, causing it to
be included in the skills distribution package (npx install-from-release,
install-skills, install-global). These scripts are build artifacts for
external repo contribution, not part of the skill consumed by agents.

Move output to dist/{skill}/ at repo root. The dist/ directory is never
copied to .claude/skills/ nor included in the release zip.

Output structure:
  skills/{skill}/scripts/  — minified, for Claude Code skill loading
  dist/{skill}/            — readable, no headers/console, for external repos
copyRecursive was additive — subdirectories removed from skills/ (like
scripts-readable/) were never deleted from .claude/skills/. Fix: remove
each destination subdirectory before copying, keeping stale files out
while preserving unmanaged files (e.g. evals/) at the top level.
@nucliweb nucliweb merged commit f3f15fd into main Mar 17, 2026
4 checks passed
@nucliweb nucliweb deleted the perf/reduce-skill-context-duplication branch March 17, 2026 23:17
@nucliweb nucliweb restored the perf/reduce-skill-context-duplication branch March 17, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant