Permissions system scales poorly

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None
    • 3048-Spigot-a25e8ed-9db9aee (MC: 1.16.5)
    • Yes

      The Advanced Achievements plugin registers a dedicated permission for each achievement created by a user. This permission determines whether a player can receive said achievement or not.

      A typical use case would be a few dozens or hundreds achievements, but some servers feature several thousands. Users have been complaining about slowness issues as the number of achievements grows, especially at startup when the plugin sets up all the achievements.

      Further investigation has shown that calls to addParent and addPermission in the Spigot API dramatically slow down as the number of registered permissions grows. Registering a single permissions takes <1ms initially, but takes >100ms after a few thousand have already been added. This will typically cause significant TPS drops on a server.

      To reproduce the issue, consider the following piece of code:

      Permission achievementParent = new Permission("achievement.*", PermissionDefault.OP);
      for (int i = 0; i < 9999; ++i) {
      	String permissionNode = "achievement." + i;
      	if (Bukkit.getPluginManager().getPermission(permissionNode) == null) {
      		Permission perm = new Permission(permissionNode, PermissionDefault.TRUE);
      		perm.addParent(achievementParent, true);
      		Bukkit.getPluginManager().addPermission(perm);
      	}
      }
      

      On my test server running Spigot 1.16.5, this takes ~11 minutes to run in total, addParent and addPermission progressively eating up more and more time. I then switched the Spigot version to 1.7.10, the same code takes only ~45s to execute. On Spigot 1.8.7, it takes ~3 minutes. It seems that the permission system's performance has regressed significantly with newer releases of Spigot.

            Assignee:
            Unassigned
            Reporter:
            Pyves
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: