Skip to content

Add view share support#165

Open
SanderMuller wants to merge 2 commits intolivewire:mainfrom
SanderMuller:feature/view-share-support
Open

Add view share support#165
SanderMuller wants to merge 2 commits intolivewire:mainfrom
SanderMuller:feature/view-share-support

Conversation

@SanderMuller
Copy link
Copy Markdown
Contributor

Removes the "Auto-injecting View::share() variables is not supported" limitation.

After all the recent performance improvements, I figured we could add this support with minor impact.

Before

Shared variables required manual access:

@blaze

<span>{{ $__env->shared('appName') }}</span>

After

Shared variables are available directly, matching Blade:

@blaze

<span>{{ $appName }}</span>

How it works

One line added to the generated function body:

extract($__env->getShared(), EXTR_SKIP);

This runs after slots and component data have already been extracted, so the priority order is: slots > props > shared, matching Blade's array_merge($shared, $data) semantics. A prop passed to a component always wins over a shared variable with the same name.

Extract shared view data into the component scope so that variables
registered via View::share() are accessible without manually calling
$__env->shared('key').

Shared data is extracted after component data (EXTR_SKIP) so that
props and slots always take priority over shared variables, matching
Blade's array_merge($shared, $data) behavior.
@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark attributes

@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark no-attributes

@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark class

@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark forwarding

@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark aware

@SanderMuller
Copy link
Copy Markdown
Contributor Author

/benchmark slot,

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Result: Attributes

Attempt Blade Blaze Improvement
#1 165.65ms 10.55ms 93.6%
#2 167.84ms 10.66ms 93.6%
#3 165.31ms 10.61ms 93.6%
#4 165.09ms 10.77ms 93.5%
#5 167.98ms 10.57ms 93.7%
#6 170.13ms 10.51ms 93.8%
#7 169.87ms 10.55ms 93.8%
#8 162.24ms 10.75ms 93.4%
#9 169.27ms 10.55ms 93.8%
#10 167.84ms 10.99ms 93.5%
Snapshot 165.81ms 10.27ms 93.8%
Result 167.84ms (~) 10.59ms (+3.1%) 93.7% (~)

Median of 10 attempts, 5000 iterations x 10 rounds, 23.39s 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: No Attributes

Attempt Blade Blaze Improvement
#1 137.00ms 6.26ms 95.4%
#2 132.99ms 6.14ms 95.4%
#3 134.26ms 6.29ms 95.3%
#4 135.61ms 6.35ms 95.3%
#5 133.75ms 6.14ms 95.4%
#6 134.86ms 6.19ms 95.4%
#7 132.22ms 6.15ms 95.3%
#8 134.22ms 6.28ms 95.3%
#9 133.85ms 6.31ms 95.3%
#10 136.67ms 6.20ms 95.5%
Snapshot 131.81ms 5.79ms 95.6%
Result 134.24ms (~) 6.23ms (+7.6%) 95.4% (~)

Median of 10 attempts, 5000 iterations x 10 rounds, 18.98s 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 236.75ms 18.16ms 92.3%
#2 240.05ms 18.13ms 92.4%
#3 236.50ms 18.39ms 92.2%
#4 231.45ms 18.36ms 92.1%
#5 236.14ms 18.34ms 92.2%
#6 234.38ms 18.09ms 92.3%
#7 235.40ms 18.73ms 92%
#8 231.20ms 18.43ms 92%
#9 232.75ms 18.58ms 92%
#10 238.43ms 18.41ms 92.3%
Snapshot 237.09ms 17.82ms 92.5%
Result 235.77ms (~) 18.38ms (+3.1%) 92.2% (-0.3%)

Median of 10 attempts, 5000 iterations x 10 rounds, 32.47s 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: Default

Attempt Blade Blaze Improvement
#1 * 347.61ms 17.28ms 95%
#2 346.05ms 16.35ms 95.3%
#3 346.06ms 16.35ms 95.3%
#4 * 342.53ms 16.18ms 95.3%
#5 346.03ms 16.11ms 95.3%
#6 348.68ms 16.51ms 95.3%
#7 * 341.07ms 15.97ms 95.3%
#8 349.08ms 16.01ms 95.4%
#9 347.62ms 16.10ms 95.4%
#10 348.30ms 16.18ms 95.4%
Snapshot 342.21ms 15.78ms 95.4%
Result 347.62ms (~) 16.18ms (+2.5%) 95.3% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 45.67s 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: Forwarding

Attempt Blade Blaze Improvement
#1 746.64ms 22.79ms 96.9%
#2 738.59ms 22.58ms 96.9%
#3 * 746.99ms 23.62ms 96.8%
#4 731.58ms 22.63ms 96.9%
#5 721.81ms 22.54ms 96.9%
#6 725.58ms 22.67ms 96.9%
#7 737.84ms 22.91ms 96.9%
#8 729.08ms 22.66ms 96.9%
#9 732.34ms 22.77ms 96.9%
#10 731.64ms 22.75ms 96.9%
Snapshot 737.99ms 21.92ms 97%
Result 731.64ms (~) 22.67ms (+3.4%) 96.9% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 93.14s 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: Aware

Attempt Blade Blaze Improvement
#1 783.32ms 39.87ms 94.9%
#2 787.27ms 40.05ms 94.9%
#3 767.75ms 39.83ms 94.8%
#4 784.25ms 39.56ms 95%
#5 775.11ms 39.52ms 94.9%
#6 788.69ms 40.03ms 94.9%
#7 790.98ms 39.44ms 95%
#8 785.59ms 39.88ms 94.9%
#9 780.54ms 40.20ms 94.8%
#10 778.45ms 39.70ms 94.9%
Snapshot 766.97ms 38.28ms 95%
Result 783.79ms (+2.2%) 39.85ms (+4.1%) 94.9% (~)

Median of 10 attempts, 5000 iterations x 10 rounds, 100.99s 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

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