Skip to content
Permalink
Browse files

[FIX JENKINS-48349] Cache permission id to avoid allocating of new st…

…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 Nov 21, 2017
1 parent 0e5db01 commit 8fa79061bb0beaf93be4e05620463fd363ac5b30
Showing with 8 additions and 1 deletion.
  1. +8 −1 core/src/main/java/hudson/security/Permission.java
@@ -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.
*
@@ -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);
@@ -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) {

0 comments on commit 8fa7906

Please sign in to comment.
You can’t perform that action at this time.