Skip to content

perf(theme): zero-allocation bitwise hex color parsing in color_parser.dart #1541

Closed

Description

@ZhuchkaTriplesix

Problem

In color_parser.dart (lib/core/theme/parser/color_parser.dart):

  1. In parseQueryaThemeColor (8-digit hex colors), four substrings are allocated (s.substring(0, 2), etc.) and parsed with int.parse(..., radix: 16).
  2. In parseVsCodeColor, 6-digit hex values allocate new strings via int.parse('FF$s', radix: 16).
  3. In formatVsCodeColor, components call toRadixString(16).padLeft(2, '0'), generating 6 to 8 intermediate string allocations per formatted color.
    When loading VS Code themes with thousands of token rules, this creates tens of thousands of temporary string objects.

Solution

  • Parse hex components in a single bitwise loop on ASCII character codes: acc = (acc << 4) | digit, eliminating all substring calls.
  • Format hex strings using a static lookup table or direct char codes.

Benefits

  • Zero substring allocations during color parsing.
  • Faster theme loading and switching.

Activity

  1. added
    performance
    enhancement
    on Oct 12, 2026
  2. added this to the 0.5.0 milestone on Oct 12, 2026
  3. added
    theme
    parser
    P2
    on Oct 12, 2026
  4. added a commit that references this issue on Oct 15, 2026
  5. ZhuchkaTriplesix commented on Oct 23, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Done in #1600.

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

    P2enhancementparserperformancetheme

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions