Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Security] Improve performance ofRoleHierarchy::buildRoleMap
method#61057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
use of an optimized role ustacking function
IMHO the test should not assert a particular role order, the method does not imply that
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Christophe Coevoet <stof@notk.org>
RoleHierarchy::buildRoleMap
methodRoleHierarchy::buildRoleMap
methodRoleHierarchy::buildRoleMap
methodRoleHierarchy::buildRoleMap
methodRoleHierarchy::buildRoleMap
methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can you please bench this patch? It should preserve the order while still providing the perf benefit:
--- a/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php+++ b/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php@@ -54,8 +54,11 @@ class RoleHierarchy implements RoleHierarchyInterface $this->map[$main] = $roles; $visited = []; $additionalRoles = $roles;- while ($role = array_shift($additionalRoles)) {+ while (null !== $role = key($additionalRoles)) {+ $role = $additionalRoles[$role];+ if (!isset($this->hierarchy[$role])) {+ next($additionalRoles); continue; }@@ -68,6 +71,8 @@ class RoleHierarchy implements RoleHierarchyInterface foreach (array_diff($this->hierarchy[$role], $visited) as $additionalRole) { $additionalRoles[] = $additionalRole; }++ next($additionalRoles); }
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Great, I'll check that this week. |
Uh oh!
There was an error while loading.Please reload this page.
use of an optimized role ustacking function
What it does and why it's needed
Note : Better in-detail explanation in there :#57322
Uses the way faster
array_pop()
function to build the role map instead ofarray shift
If it modifies existing behavior, include a before/after comparison
At first, it would look like this function swap could change slightly the ordering of the array produced by the
RoleHierarchy::buildRoleMap
method and it does it in a way. I find that it does not change the behaviour of our app.I would not expect most other apps too break because I don't find many reasons to rely on the ordering of roles in hierarchies. Furthermore,
buildRoleMap
is a protected method serving the publicgetReachableRoleNames
which does not imply a particular ordering (rightfully so IMHO).Testing
As it does not change or introduce any behavious per say, this performance increase rely on old tests passing again.
If I am not mistaken, the current
testGetReachableRoleNames()
still passes even tho it asserts a specific ordering. I still changed the assertion so it does not convey any false premises.