Use trie for removeStringLiteralsMatchedByTemplateLiterals#3331
Open
eps1lon wants to merge 1 commit intomicrosoft:mainfrom
Open
Use trie for removeStringLiteralsMatchedByTemplateLiterals#3331eps1lon wants to merge 1 commit intomicrosoft:mainfrom
eps1lon wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Optimize removeStringLiteralsMatchedByTemplateLiterals by building a prefix trie from TemplateLiteralType patterns and using O(L) trie traversal per string literal instead of O(m) linear scan across all templates. StringMappingType templates (which cannot be trie-indexed) are checked separately. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ports the TypeScript change to speed up removeStringLiteralsMatchedByTemplateLiterals by indexing template-literal patterns by their leading text, reducing repeated full scans when pruning redundant string-literal constituents during union reduction.
Changes:
- Introduces an internal trie node type for indexing template-literal prefixes.
- Adds trie construction + lookup helpers to find a matching template literal efficiently.
- Refactors
removeStringLiteralsMatchedByTemplateLiteralsto use the trie (when beneficial) and to separately handle template literals vs string-mapping patterns.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/checker/types.go | Adds templateLiteralTrieNode type to support prefix trie indexing. |
| internal/checker/relater.go | Adds trie build + lookup helpers that leverage texts[0] as the prefix key for template-literal matching. |
| internal/checker/checker.go | Refactors string-literal pruning to use trie-based matching for template literals and preserves string-mapping handling. |
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.
Port of microsoft/TypeScript#63343
Actual implementation is vibe-coded with Claude Opus 4.6 (1M context)