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

Merged
fabpot merged 1 commit intosymfony:7.4fromsimonjamain:fix-57322
Aug 23, 2025

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.

@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
@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.

@fabpot
Copy link
Member

Thank you@simonjamain.

@fabpotfabpot merged commit44f6c85 intosymfony:7.4Aug 23, 2025
10 of 12 checks passed
fabpot added a commit that referenced this pull requestAug 24, 2025
…nicolas-grekas)This PR was merged into the 7.4 branch.Discussion----------[Security] Preserve ordering of roles in RoleHierarchy| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| Issues        | -| License       | MITAs suggested in#61057/cc `@simonjamain`Commits-------d4338b1 [Security] Preserve ordering of roles in RoleHierarchy
This was referencedOct 27, 2025
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

@fabpotfabpotfabpot approved these changes

@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

7 participants

@simonjamain@fabpot@nicolas-grekas@stof@OskarStark@carsonbot@simonjamain-gp

[8]ページ先頭

©2009-2025 Movatter.jp