Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
Symfony version(s) affected
7.1.1
Description
TheRoleHierarchy::buildRoleMap()
can be slow when there is a big hierrachy to build.
For context, in our project (https://gitlab.com/incubateur-territoires/france-relance/silab/silab-front) we have a dynamic role tree that rely extensively on the symfony implementation ofRoleHierarchy
.
After using a profiler we saw that it took 9 seconds to build our role map (~4s in production).
The use ofarray_shift
in the folowing line is the culprit :
while ($role =array_shift($additionalRoles)) { |
We changed it for anarray_pop
which is known to have abetter complexity and we dropped from ~9s to ~50ms in dev env (RoleHierarchy::buildRoleMap()
execution time).
AFAIK thearray_shift
behavior is not needed in that loop andarray_pop
return the same elements in the role map.
How to reproduce
You can time the execution of the main buildRoleMap loop (either with a profiler or with your logger) with the originalarray_shift
and with thearray_pop
Possible Solution
replace the use ofarray_shift
witharray_pop
in the folowing line
while ($role =array_shift($additionalRoles)) { |
Additional Context
No response