Skip to content

perf(theme): zero-allocation scope prefix matching in TokenStyleResolver #1530

Open

Description

@ZhuchkaTriplesix

Problem

In TokenStyleResolver._scopePrefixes (lib/core/theme/parser/token_style_resolver.dart), resolving uncached syntax highlighting scopes splits the scope string (scope.split('.')) and generates sublists joined by dot (parts.sublist(0, i).join('.')).
For deeply nested syntax token scopes, this allocates multiple intermediate lists and strings on every uncached token lookup.

Solution

  • Traverse scope prefixes backwards using scope.lastIndexOf('.') and yield slices via scope.substring(0, dot).
  • Eliminate all intermediate List<String> and join('.') calls.

Benefits

  • 0 List allocations during scope prefix resolution.
  • Faster syntax highlight cold start and theme switching.

Activity

  1. added this to the 0.5.0 milestone on Oct 12, 2026
  2. added
    performanceTheme parser epic label: performance
    enhancementNew feature or request
    themeTheming, colors, VS Code themes
    parserTheme parser epic label: parser
    P2Medium priority / Parity & Refactoring
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringenhancementNew feature or requestparserTheme parser epic label: parserperformanceTheme parser epic label: performancethemeTheming, colors, VS Code themes

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions