Skip to content

⚡ Bolt: TuiColor.ParseFunctional String Parsing Optimization#287

Open
tedd wants to merge 1 commit into
mainfrom
bolt-tuicolor-parse-optimization-271079060976873440
Open

⚡ Bolt: TuiColor.ParseFunctional String Parsing Optimization#287
tedd wants to merge 1 commit into
mainfrom
bolt-tuicolor-parse-optimization-271079060976873440

Conversation

@tedd

@tedd tedd commented Jun 25, 2026

Copy link
Copy Markdown
Owner

💡 Hypothesis:
The string allocation footprint inside TuiColor.ParseFunctional() when resolving rgb() and rgba() CSS-style definitions creates unnecessary GC pressure during dynamic UI updates. string.Split(',') and .Substring() calls create multiple intermediate objects.

🎯 Execution:
Refactored TuiColor.ParseFunctional, ParseColorComponent, and ParseAlphaComponent to completely eliminate string allocations by utilizing:

  • ReadOnlySpan<char> parameter passing.
  • String slicing via .Slice().
  • .Split(stackalloc Range[4], ',') to manually separate comma-delimited components onto the stack.

📊 Empirical Impact:

Method Mean Error StdDev Gen0 Allocated
ParseFunctional_Legacy_Rgba 392.1 ns 2.62 ns 2.33 ns 0.0138 336 B
ParseFunctional_Optimized_Rgba 217.8 ns 1.20 ns 1.12 ns - -
ParseFunctional_Legacy_Rgb 261.6 ns 0.93 ns 0.83 ns 0.0105 256 B
ParseFunctional_Optimized_Rgb 120.4 ns 0.35 ns 0.29 ns - -

Time complexity remains $O(N)$, but space complexity is reduced from $O(N)$ arrays to $O(1)$ stack allocations. Allocations reduced to $0$ Bytes. Execution latency reduced by ~45-50%.

🔬 Verification Protocol:

  1. Build Tedd.TUI.Benchmarks.
  2. Execute: dotnet run -c Release --project src/Tedd.TUI.Benchmarks/ --filter "*ParseFunctionalBenchmark*"

PR created automatically by Jules for task 271079060976873440 started by @tedd

Replaced `string.Split()` and `.Substring()` with `ReadOnlySpan<char>` slicing and `stackalloc Range[]` inside `TuiColor.ParseFunctional()`. This eliminated GC allocations and halved execution time for CSS-style color parsing.

Co-authored-by: tedd <493224+tedd@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant