From 72477dec0cb29610a9ee8a2324687942c0209b14 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 19:31:30 +0000 Subject: [PATCH] docs: add performance tips to readme Co-Authored-By: Claude Sonnet 5.5 --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 356f5df..c9ee1f0 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,14 @@ for (const rule of ast) { - **Location tracking with no penalty** — full line, column, and offset data without slowing the parser down - **No syntax validation** — skipping spec checks and MDN data means nothing gets in the way of speed +### Performance tips + +- **Skip parsing what you don't need.** Not parsing is always faster: set `parse_values`, `parse_selectors` or `parse_atrule_preludes` to `false`. +- **Use `node.type` or `is_*()` guards; never `node.type_name`.** `type_name` is a string meant for debugging. +- **Use `node.for_each(cb)` instead of `for...of`.** Iterating a node uses a generator; `for_each` allocates nothing. Return `false` to stop early. +- **Prefer `walk()` and `walk_declarations()`/`walk_selectors()`/`walk_values()`** over hand-rolled recursion when you only need certain nodes. +- **Avoid `node.clone()` in hot paths.** Only clone when you need a mutable copy. + ## API Everything is exported from the package root. Each part is also available from its own entry point, so you can import only what you need. Node properties and return types ship as TypeScript types.