Repository navigation
perf!: use switch for type_name and remove TYPE_NAMES - #314
Merged
Merged
Conversation
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>
Contributor
🎉 Package Size Decrease
|
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CSSNode#type_nameis now aswitchon the numeric type instead of an object lookup.TYPE_NAMESexport is removed. Usenode.type_nameinstead ofTYPE_NAMES[node.type].TypeNameis now an explicit string-literal union (it used to be derived fromTYPE_NAMES).Benchmarks
pnpm run benchmark,walk (node.type_name)in ops/sec, before → after:The
walk (node.type)control rows were flat between runs, and tokenize, parse andtraversedid not regress. In a micro-benchmark that reads onlytype_nameon 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
.tssources directly was much slower in my testing, but the published bundle is unaffected.Test plan
pnpm vitest --runpnpm run lintpnpm run checkpnpm knipGenerated by Claude Code