-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[11.x] Blade @include performance #54633
Conversation
Nice! |
I love attention to detail like this! Nice work :) |
Maybe we should change |
Arr::except also supports |
@AlliBalliBaba Would you mind sharing what you use to make these performance comparisons and the flamegraph? Do you use php-spx? Do you have any gist or something to help get started with this? Thanks! |
You can create nice flamegraphs for pretty much any programming language using [brendangregg's flamegraph repo](https://github.com/brendangregg/FlameGraph]. Also I forgot to mention: in order to create more detailed flamegraphs, you might want to spam a specific endpoints with many requests. There are some command line tools that let you do this easily, like wrk or |
@AlliBalliBaba Nice! I'll play with this right away. |
Hm even though this broke the Bladestan tests, this at least gives me some hope that there is a decent chance we could clean up some of the generated code to make it a bit easier to analyze :D |
After looking at some flamegraphs with xdebug, I noticed that for templates with many includes a lot of time was being spent on this line:
framework/src/Illuminate/View/Compilers/BladeCompiler.php
Line 935 in 17786ca
After looking at what
Arr::except
does, I noticed there's a built in function that does the same and can be used in this case instead:array_diff_key
. array_diff_key exists sincePHP 5.1
and excludes the keys of the second array from the first one.In the below flamegraph you can see, that the built in function is around ~500% more efficient

(comparison done by excluding 2 keys from an array with 100 keys)
Using the built in function improves performance for Views with lots of
@includes
and generally makes the<?php
snippet more portable (it doesn't need to access a namespaced class)