Skip to content

Use trie for removeStringLiteralsMatchedByTemplateLiterals#3331

Open
eps1lon wants to merge 1 commit intomicrosoft:mainfrom
eps1lon:sebbie/ftl/batched-removal
Open

Use trie for removeStringLiteralsMatchedByTemplateLiterals#3331
eps1lon wants to merge 1 commit intomicrosoft:mainfrom
eps1lon:sebbie/ftl/batched-removal

Conversation

@eps1lon
Copy link
Copy Markdown
Contributor

@eps1lon eps1lon commented Apr 2, 2026

Port of microsoft/TypeScript#63343

Actual implementation is vibe-coded with Claude Opus 4.6 (1M context)

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]>
@eps1lon eps1lon marked this pull request as ready for review April 2, 2026 20:19
Copilot AI review requested due to automatic review settings April 2, 2026 20:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 removeStringLiteralsMatchedByTemplateLiterals to 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.

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