Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Open
simonjamain wants to merge4 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromsimonjamain:fix-57322

Conversation

simonjamain
Copy link

@simonjamainsimonjamain commentedJul 7, 2025
edited by OskarStark
Loading

QA
Branch?7.4
Bug fix?no
New feature?no (perf)
Deprecations?no
IssuesFix#57322
LicenseMIT

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 fasterarray_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 theRoleHierarchy::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 currenttestGetReachableRoleNames() still passes even tho it asserts a specific ordering. I still changed the assertion so it does not convey any false premises.

use of an optimized role ustacking function
IMHO the test should not assert a particular role order, the method does not imply that
Co-authored-by: Christophe Coevoet <stof@notk.org>
@GromNaNGromNaN changed the titleFix 57322[Security] Improve performance ofRoleHierarchy::buildRoleMap methodJul 7, 2025
@carsonbotcarsonbot changed the title[Security] Improve performance ofRoleHierarchy::buildRoleMap methodImprove performance ofRoleHierarchy::buildRoleMap methodJul 7, 2025
@carsonbotcarsonbot changed the titleImprove performance ofRoleHierarchy::buildRoleMap method[Security] Improve performance ofRoleHierarchy::buildRoleMap methodJul 8, 2025
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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);             }

@symfonysymfony deleted a comment fromcarsonbotJul 8, 2025
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
@simonjamain
Copy link
Author

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);             }

Great, I'll check that this week.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

performance issues with RoleHierarchy
6 participants
@simonjamain@nicolas-grekas@stof@OskarStark@carsonbot@simonjamain-gp

[8]ページ先頭

©2009-2025 Movatter.jp