Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-55803] - Attempt to solve issue:removing the intermediate collections created each time getRolesHavingPermission() is invoked #54

Merged
merged 26 commits into from
Feb 11, 2019

Conversation

deepanshnagaria
Copy link
Contributor

my attempt to fix the issue(55803,Performance: Replace RoleMap#getRolesHavingPermission() usages by iterators) by removing the intermediate collections each time the method is invoked. i did so by implementing the logic of the for loop in the roleWalker() itself. I removed the now not used method getRolesHavingPermission().

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepanshnagaria could you please the formatting?

In Java the common formatting is

if (something) {
   // ...
} else if (somethingElse) {
   // ...
} else {
   // ..
}

The logic itself looks Ok

if(this.grantedRoles.get(role).contains(sid)) {
final Set<Permission> permissions = new HashSet<>();
final Permission per = p;
final boolean[] temp = {false};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional would be recommended, but ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sir i didn't understand.... Can you clarify a bit....?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepanshnagaria
Copy link
Contributor Author

Sorry for the issue in formatting i took reference from if else instead of this: (. I shall do that. Sorry again for repeated issues in formatting, i shall try to ignore further such issues.

Copy link
Member

@runzexia runzexia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks ok,only some formatting problems.
And I was wondering if I could break the walker when the perform was true, just a possible improve.

// Walk through the roles, and only add the roles having the given permission,
// or a permission implying the given permission
new RoleWalker() {
public void perform(Role current) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to add an overide annotation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@deepanshnagaria
Copy link
Contributor Author

@runzexia I myself thought of breaking the RoleWalker but with current implementation it doesn't seem to be possible. But we can do the same by not calling the RoleWalker and implementing the logic of walk function, that could be done. Should I do that?

@runzexia
Copy link
Member

runzexia commented Jan 31, 2019

I think you can try to do that, I don't know how oleg thinks, this PR already looks good.
@deepanshnagaria

@deepanshnagaria
Copy link
Contributor Author

I shall do that in the next commit, it won't take much i think. Thanks for the review.

@deepanshnagaria
Copy link
Contributor Author

@runzexia this commit contains changes for breaking the loop. cc: @oleg-nenashev

@oleg-nenashev
Copy link
Member

@deepanshnagaria @runzexia

I myself thought of breaking the RoleWalker but with current implementation it doesn't seem to be possible. But we can do the same by not calling the RoleWalker and implementing the logic of walk function, that could be done. Should I do that?

Yes, breaking the cycle will be an interesting change

RoleWalker is a part of the plugin codebase:

private abstract class RoleWalker {
RoleWalker() {
walk();
}
/**
* Walk through the roles.
*/
public void walk() {
Set<Role> roles = RoleMap.this.getRoles();
Iterator<Role> iter = roles.iterator();
while (iter.hasNext()) {
Role current = iter.next();
perform(current);
}
}
/**
* The method to implement which will be called on each {@link Role}.
*/
abstract public void perform(Role current);

My suggestion would be to create a follow-up ticket to support breaking the cycle from RoleWalker API (e.g. a new abort() method), and then this change can be landed in a follow-up PR.

@deepanshnagaria
Copy link
Contributor Author

deepanshnagaria commented Feb 1, 2019

@oleg-nenashev I have created an issue https://issues.jenkins-ci.org/browse/JENKINS-55916 adding a point for memory, do tell if changes are required.
cc: @runzexia

@deepanshnagaria
Copy link
Contributor Author

deepanshnagaria commented Feb 1, 2019

I have updated this commit in sink with changes in #58 please suggest changes if required. @runzexia @oleg-nenashev

@oleg-nenashev
Copy link
Member

@deepanshnagaria there is a minor merge conflict after integration of other PRs. Are you able to resolve it? Or do you need some assistance?

@deepanshnagaria
Copy link
Contributor Author

@deepanshnagaria there is a minor merge conflict after integration of other PRs. Are you able to resolve it? Or do you need some assistance?

yeah i shall do resolve that.

@deepanshnagaria
Copy link
Contributor Author

ignore last commit pls

@deepanshnagaria deepanshnagaria changed the title [JENKINS-55803] - Attempt to solve issue [JENKINS-55803] - Attempt to solve issue:removing the intermediate collections each time getRolesHavingPermission() is invoked Feb 6, 2019
@oleg-nenashev oleg-nenashev self-requested a review February 6, 2019 16:37
@deepanshnagaria deepanshnagaria changed the title [JENKINS-55803] - Attempt to solve issue:removing the intermediate collections each time getRolesHavingPermission() is invoked [JENKINS-55803] - Attempt to solve issue:removing the intermediate collections created each time getRolesHavingPermission() is invoked Feb 9, 2019
@oleg-nenashev
Copy link
Member

@deepanshnagaria could you please configure your IDE to disable automatic code reformatting? Even if the code formatting is not good, massive formatting changes usually leads to merge conflicts. It is better to handle it in a separate PR next time

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from the code formatting

@deepanshnagaria
Copy link
Contributor Author

LGTM apart from the code formatting

I have solved most of the formatting issues. Thanks for the review. Think, that it is ready for merge. Suggest changes if needed. @oleg-nenashev @runzexia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants