Skip to content

Performance - class style fast path#157

Closed
SanderMuller wants to merge 2 commits intolivewire:mainfrom
SanderMuller:autoresearch/class-style-fast-path
Closed

Performance - class style fast path#157
SanderMuller wants to merge 2 commits intolivewire:mainfrom
SanderMuller:autoresearch/class-style-fast-path

Conversation

@SanderMuller
Copy link
Copy Markdown
Contributor

When class() or style() is called with a plain string (the common case), bypass the full merge() cycle and directly append the value to the attributes array. Avoids the escape loop, attribute partitioning, and array_merge overhead.

Biggest single win: -66% on the class benchmark (blaze/blade ratio).

When called with a plain string (the common case), bypass the full merge() cycle entirely — directly append the class value to the existing attributes array. This avoids the escape loop, partitioning, and array_merge overhead.

Benchmarks show -66% improvement on the class benchmark (blaze/blade ratio).
Symmetric optimization to the class() fast path — directly append style values when given a plain string, bypassing the full merge() cycle.
@SanderMuller SanderMuller changed the title Autoresearch/class style fast path Performance - class style fast path Mar 28, 2026
@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark class

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 28, 2026

Benchmark Result: Default

Attempt Blade Blaze Improvement
#1 343.05ms 15.77ms 95.4%
#2 343.58ms 15.64ms 95.4%
#3 342.02ms 15.97ms 95.3%
#4 347.83ms 15.90ms 95.4%
#5 342.64ms 15.85ms 95.4%
#6 351.02ms 15.81ms 95.5%
#7 349.20ms 16.07ms 95.4%
#8 341.42ms 15.95ms 95.3%
#9 347.39ms 15.83ms 95.4%
#10 * 345.19ms 16.25ms 95.3%
Snapshot 343.96ms 16.00ms 95.3%
Result 343.58ms (~) 15.85ms (~) 95.4% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 45.55s total

To run a specific benchmark, comment /benchmark <name> where name is one of: attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Result: Class

Attempt Blade Blaze Improvement
#1 239.29ms 13.67ms 94.3%
#2 238.79ms 13.49ms 94.4%
#3 234.62ms 13.21ms 94.4%
#4 237.78ms 13.33ms 94.4%
#5 239.65ms 13.38ms 94.4%
#6 233.81ms 13.52ms 94.2%
#7 235.35ms 13.42ms 94.3%
#8 236.71ms 13.83ms 94.2%
#9 231.54ms 13.69ms 94.1%
#10 * 232.39ms 14.17ms 93.9%
Snapshot 239.98ms 18.00ms 92.5%
Result 236.71ms (~) 13.49ms (-25.1%) 94.3% (+1.8%)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 32.16s total

To run a specific benchmark, comment /benchmark <name> where name is one of: attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot

@SanderMuller SanderMuller marked this pull request as ready for review March 28, 2026 21:03
@ganyicz
Copy link
Copy Markdown
Collaborator

ganyicz commented Mar 29, 2026

I like this but feels like we're duplicating a lot of code also in #161. Would you be able to merge these together into one PR and see if we can extract some of the logic into separate methods please?

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