Skip to content

perf!: use switch for type_name and remove TYPE_NAMES - #314

Merged
bartveneman merged 2 commits into
mainfrom
claude/dreamy-dijkstra-v4cwve
Oct 19, 2026
Merged

bartveneman merged 2 commits into
mainfrom
claude/dreamy-dijkstra-v4cwve

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Summary

  • CSSNode#type_name is now a switch on the numeric type instead of an object lookup.
  • Breaking: the TYPE_NAMES export is removed. Use node.type_name instead of TYPE_NAMES[node.type].
  • TypeName is now an explicit string-literal union (it used to be derived from TYPE_NAMES).
  • README example updated.

Benchmarks

pnpm run benchmark, walk (node.type_name) in ops/sec, before → after:

File Before After Change
Nerdy.dev 3687 3820 +3.6%
CSS Tricks 411 418 +1.7%
Bootstrap 1956 2027 +3.6%
Tailwind 137 146 +6.6%

The walk (node.type) control rows were flat between runs, and tokenize, parse and traverse did not regress. In a micro-benchmark that reads only type_name on every Bootstrap node, the switch was about 35% faster (about 12.2 ms down to 7.6 ms).

The switch relies on bundling to inline the numeric constants. Running the unbundled .ts sources directly was much slower in my testing, but the published bundle is unaffected.

Test plan

  • pnpm vitest --run
  • pnpm run lint
  • pnpm run check
  • pnpm knip

Generated by Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
type_name is now backed solely by a switch; use node.type_name instead of
TYPE_NAMES[node.type].

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Package Size Decrease

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
@projectwallace/css-parser 46.3 kB 46 kB -233 B

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@projectwallace/css-parser@d2eb86c

commit: d2eb86c

@bartveneman
bartveneman merged commit 32a6e4c into main Oct 19, 2026
16 checks passed
@bartveneman
bartveneman deleted the claude/dreamy-dijkstra-v4cwve branch October 19, 2026 07:27
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.

2 participants