Skip to content

Refactor to AST - #197

Draft
ganyicz wants to merge 58 commits into
mainfrom
filip/parser-refactor
Draft

Refactor to AST#197
ganyicz wants to merge 58 commits into
mainfrom
filip/parser-refactor

Conversation

@ganyicz

@ganyicz ganyicz commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Following #193, which adds support for parsing directives, this PR refactors rest of Blaze to take advantage of that:

  • Compiling @props and @aware directives
  • Compiling @unblaze blocks
  • Analyzing @blaze, @props and @aware directives
  • Extracting use statements from @php blocks and @use directives

Previously we used DirectiveCompiler for this. This class hacked into Laravel's BladeCompiler to delegate the parsing of directives to Blade, however in #193 we brought most of that logic into our tokenizer and directives are now part of the AST.

After this PR, all analysis and compilation is now driven by the AST, including skipping over <?php, @php and @verbatim blocks, which was previously also done by hacking into BladeCompiler.

This required bigger structural changes however creates multiple benefits:

  • Faster compilation: making Blaze only ~5% slower than Blade (prev. 900% slower)
  • Unified approach: everything is now driven by the AST
  • Dropping reliance on internal state of BladeCompiler in most places

The performance improvement is mostly the result of caching the AST and dropping the DirectiveCompiler which used reflection and had to run multiple regexes over the entire template repeatedly.

@ganyicz
ganyicz marked this pull request as draft August 6, 2026 12:51
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Benchmark Result: Default

Attempt Blade Blaze Change
#1 365.34ms 14.73ms 96%
#2 363.56ms 15.02ms 95.9%
#3 362.06ms 14.69ms 95.9%
#4 364.47ms 14.87ms 95.9%
#5 368.33ms 14.83ms 96%
#6 361.97ms 15.31ms 95.8%
#7 360.68ms 15.04ms 95.8%
#8 366.10ms 14.66ms 96%
#9 366.85ms 14.72ms 96%
#10 367.64ms 14.89ms 95.9%
Snapshot 363.13ms 14.70ms 96%
Result 364.91ms (~) 14.85ms (~) 95.9% (~)

Median of 10 attempts, 5000 iterations x 10 rounds, 47.83s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

@ganyicz

ganyicz commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/benchmark compilation

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Benchmark Result: Compilation

Attempt Blade Blaze Change
#1 2.21ms 2.33ms -5.4%
#2 2.27ms 2.35ms -3.5%
#3 2.22ms 2.34ms -5.4%
#4 2.24ms 2.34ms -4.5%
#5 2.23ms 2.34ms -4.9%
#6 2.24ms 2.36ms -5.4%
#7 2.22ms 2.32ms -4.5%
#8 2.24ms 2.36ms -5.4%
#9 2.27ms 2.37ms -4.4%
#10 2.25ms 2.36ms -4.9%
Snapshot 2.20ms 21.11ms -859.5%
Result 2.24ms (~) 2.34ms (-88.9%) -4.5% (+855%)

Median of 10 attempts, 5000 iterations x 10 rounds, 2.87s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

@ganyicz

ganyicz commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/benchmark compilation

@ganyicz

ganyicz commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/benchmark compilation

@ganyicz

ganyicz commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/benchmark compilation

@ganyicz ganyicz changed the title Refactor parser Refactor to AST Aug 9, 2026
@ganyicz
ganyicz marked this pull request as ready for review August 9, 2026 21:31
@ganyicz
ganyicz marked this pull request as draft August 9, 2026 23:29
@ganyicz

ganyicz commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

/benchmark compilation

@ganyicz
ganyicz marked this pull request as ready for review August 10, 2026 08:29
@ganyicz
ganyicz marked this pull request as draft August 10, 2026 09:49
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