# Performance Lint Rules > Guía de rendimiento para implementaciones de reglas del linter de Oxc. Úsalo solo al revisar código Rust bajo crates/oxc_linter/src/rules/ o al auditar esas reglas explícitamente. Fuente: https://skillsagentes.com/skills/oxc-project/oxc/performance-lint-rules Markdown: https://skillsagentes.com/skills/oxc-project/oxc/performance-lint-rules.md Repositorio: https://github.com/oxc-project/oxc Autor: oxc-project Licencia: MIT Actualizado: el mes pasado Coste de contexto: 52 tok instalada, 1.1k tok al activarse, 1.1k tok con todos los archivos del bundle Bundle: 1 archivo, 4 KB Permisos que pide: ninguno declarado ## Instalación Un skill son archivos markdown: los mismos archivos valen para cualquier agente y lo único que cambia es el directorio de destino, es decir la bandera `--agent`. Añade `-g` para instalarlo en todos los proyectos de la máquina. ```bash # Claude Code npx -y skills add oxc-project/oxc --skill performance-lint-rules --agent claude-code # Cursor npx -y skills add oxc-project/oxc --skill performance-lint-rules --agent cursor # Codex npx -y skills add oxc-project/oxc --skill performance-lint-rules --agent codex # Gemini CLI npx -y skills add oxc-project/oxc --skill performance-lint-rules --agent gemini # Windsurf npx -y skills add oxc-project/oxc --skill performance-lint-rules --agent windsurf # Cline npx -y skills add oxc-project/oxc --skill performance-lint-rules --agent cline ``` ## Qué hace - Recomienda poner los chequeos de tipo de nodo AST al inicio de 'run' para que lintgen derive NODE_TYPES más estrechos - Ordena las comprobaciones de más baratas/selectivas a más costosas antes de hacer lookups semánticos o asignaciones - Aconseja retrasar la preparación de diagnósticos, fixes y strings hasta que exista un candidato real que reportar - Sugiere iterar sobre el conjunto más pequeño posible (símbolos, listas precomputadas) en vez de recorrer todo el AST ## Cuándo usarla - Se revisa código Rust de reglas bajo crates/oxc_linter/src/rules/ - Se audita explícitamente el rendimiento de esas reglas ## Cuándo no - No se está revisando ni auditando código de reglas del linter de Oxc ## Qué la activa - "Revisa el rendimiento de esta regla del linter de Oxc" - "Audita crates/oxc_linter/src/rules/no-foo.rs para optimizarla" ## Archivos - SKILL.md — 4 KB ## SKILL.md Reproducido tal cual desde oxc-project/oxc bajo MIT. Esta sección es el documento original y está en inglés. ## Performance Guidelines ### Prefer top-level node kind checks Put node kind checks at the rule entry point. If a rule only handles a few syntactic forms, start `run` with an `AstKind` match and return for all other nodes, even when a helper filters again internally. This lets lintgen derive narrower `NODE_TYPES` and avoids dispatching the rule on unrelated AST nodes. After changing the relevant node kinds for a rule, regenerate the rule runner with `cargo lintgen` and consider adding or updating `assert_rule_runs_on_node_types` coverage in `crates/oxc_linter/src/rule.rs`. Implement only the needed entry point. If a rule is a whole-file pass over semantic indexes, use `run_once` by itself. Implementing both `run` and `run_once` prevents useful node-type narrowing. ### Do cheaper checks first Order checks from cheapest and most selective to most expensive. Return quickly for common non-matches before doing semantic lookups, allocations, or deeper traversal. - Matching a small fixed string set with `matches!` before semantic checks. - Rejecting lowercase identifiers before global-object checks when only constructors can match. - Checking whether a JSX attribute starts with `aria-` before lowercasing it. - Checking for required syntax such as a `key` prop before looking up callback parameter symbols. - Checking `source_range(span).contains("this")` before running a visitor that only finds `this`. ### Delay expensive context Most files do not contain lint errors. Do not prepare diagnostics, labels, help text, fix data, ancestors, symbols, JSX element types, or replacement strings until the rule has found a syntactic candidate that could actually report. ### Iterate over the smallest set possible - Use `run_once` when the rule only needs a whole-file pass and does not need to run on every node. - Iterate over symbols instead of AST nodes when looking for references to specific names. - Prefer targeted lists or semantic data over broad AST traversal when available. - For name-based binding checks, use `ctx.scoping().get_binding(scope_id, name)` instead of scanning every binding in `get_bindings(scope_id)`. - For global or unresolved identifier checks, start from `ctx.scoping().root_unresolved_references().get(name)` for the small set of relevant names instead of visiting every `IdentifierReference`. - When iterating unresolved references, still verify the reference is the right kind: skip references with a symbol, type-only references, and nodes whose `AstKind` is not the expected identifier or member access. - When checking imported specifiers or exported names, iterate the concrete specifiers or precomputed export set rather than scanning all root bindings for every item. Use precomputed `FxHashSet`s only when many symbols need the same membership test. Prefer keyed semantic lookup when each lookup already has an exact name. ### Avoid unnecessary regular expressions Avoid regular expressions when byte or string checks are enough: `contains`, `starts_with`, `ends_with`, or matching a small fixed set. For hot comment or string scanning paths, prefer a cheap `memchr` or byte search to reject most inputs, then parse only candidates. Preserve regex semantics when replacing one, especially identifier boundaries, optional prefixes, and multiline whitespace. ### Avoid heap allocations - Use copy-on-write utilities when a value usually does not need to change. - Avoid intermediate `Vec`s and `String`s when iteration or borrowed data is enough. - Keep temporary data on the stack when practical. - Delay allocation until a diagnostic, fix, or transformed value is actually needed. - Use allocation-free ASCII comparisons such as `starts_with_ignore_case` before calling `cow_to_ascii_lowercase`. - Use byte scans such as `as_bytes().array_windows()` for simple ASCII patterns like escape sequences. - Reserve hash maps or sets when the final size is known. - Avoid building a `HashSet` just to check names that can be looked up directly in scoping data. ## Dónde encaja - Categoría: [Herramientas para desarrolladores](https://skillsagentes.com/categorias/herramientas-desarrollo.md) — Skills que cambian cómo tu agente escribe, revisa y despliega código. - Creador: [oxc-project](https://skillsagentes.com/creators/oxc-project.md) — 4 skills en el directorio - [Todas las skills](https://skillsagentes.com/skills.md) - [Ranking de instalaciones](https://skillsagentes.com/ranking.md) ## Otras skills del mismo repositorio - [Migrate Oxfmt](https://skillsagentes.com/skills/oxc-project/oxc/migrate-oxfmt.md): Guía para migrar un proyecto JavaScript/TypeScript de Prettier o Biome a Oxfmt. - [Migrate Oxlint](https://skillsagentes.com/skills/oxc-project/oxc/migrate-oxlint.md): Guía para migrar un proyecto JavaScript/TypeScript de ESLint a Oxlint. - [Insta Snapshots](https://skillsagentes.com/skills/oxc-project/oxc/insta-snapshots.md): Guía para trabajar con y actualizar los tests de snapshot de insta en Oxc sin necesitar interacción con la terminal. --- Skills Agentes · [Índice de páginas en markdown](https://skillsagentes.com/sitemap.md) · [Inicio](https://skillsagentes.com/index.md)