Skip to content

Commit

Permalink
[FIX JENKINS-48349] Cache permission id to avoid allocating of new st…
Browse files Browse the repository at this point in the history
…rings

Every request that comes from Jelly is checked against Permissions.
As result it leads to a call of `getId` method that produces the new string.
Usually it's not a problem, but in case of stop-the-world pause user requests are accumulated.
So, once pause is finished, we forcibly allocated tons of strings for
every request. That leads to new stop-the-world pause. (And this cycle
can repeat multiple times)

(cherry picked from commit b2c40cb)
  • Loading branch information
Jimilian authored and olivergondza committed Jan 3, 2018
1 parent 0e5db01 commit 8fa7906
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/main/java/hudson/security/Permission.java
Expand Up @@ -68,6 +68,9 @@ public int compare(@Nonnull Permission one, @Nonnull Permission two) {

public final @Nonnull PermissionGroup group;

// if some plugin serialized old version of this class using XStream, `id` can be null
private final @CheckForNull String id;

/**
* Human readable ID of the permission.
*
Expand Down Expand Up @@ -158,6 +161,7 @@ public Permission(@Nonnull PermissionGroup group, @Nonnull String name,
this.impliedBy = impliedBy;
this.enabled = enable;
this.scopes = ImmutableSet.copyOf(scopes);
this.id = owner.getName() + '.' + name;

group.add(this);
ALL.add(this);
Expand Down Expand Up @@ -222,7 +226,10 @@ public boolean isContainedBy(@Nonnull PermissionScope s) {
* @see #fromId(String)
*/
public @Nonnull String getId() {
return owner.getName()+'.'+name;
if (id == null) {
return owner.getName() + '.' + name;
}
return id;
}

@Override public boolean equals(Object o) {
Expand Down

0 comments on commit 8fa7906

Please sign in to comment.