Question about PEX (performance with inheritances)

Back in the old days, PEX and other permission managers tended to have a really bad performance on *ukkit servers for things like ‘prison servers’ where most folks had ranks A-Z as an inheritance chain and in fact “inheritance chaining” was the cause of bad peformance (that and the wildcarding)

While such a complex system will always require more than a simple player/mod/admin configuration anyways, my question is if the new Sponge core system, and PEX core, is able to handle inheritance chains much better now or is just as bad or even worse off than before?

1 Like

https://github.com/PEXPlugins/PermissionsEx/blob/master/permissionsex-core/src/main/java/ninja/leaping/permissionsex/subject/InheritanceSubjectDataBaker.java

Pex not only bakes / flattens the inheritance, but additionally caches permission queries.

Thanks for prompt reply. The codeskillz in that pastebin are many levels above my ability to comprehend esp since I am very unfamilar with pex’s infrastructure and systems in the first place.

Can you explain what is meant by baking and flattening the inheritance?

1 Like

I’m not 100% familiar with pex’s code. But you mentioned that you expected that long inheritance would end up being slow right?

So you are expecting a lookup to Z->Y->X->…->A right?

So if you know you need to be performant, you can do all the lookups at once, at the start, so you would only need to check Z and not fallback to Y, since the data hasn’t been changed you can rely on it to be correct.

e.g.

A {
permission.x = true;
}

B inherits A {
permission.y = true;
}
C inherits B {
permission.z = true;
}

could be flattened to.

A {
permission.x = true;
}

B {
permission.x = true;
permission.y = true;
}
C {
permission.x = true;
permission.y = true;
permission.z = true;
}

Understand? Of course in practise it’s more complicated, because you have to decide when to “re-bake” when permissions are changed, as well as working out how to deal with contexts etc.

ahkay so its like… for our readability and design, we structure with inheritance … but under the hood, it treats it just like a pastebin-from-hell redundancy…

If thats how it did it before as well, then I guess the problem comes in when you have lots and lots of ranks and a couple new permissions each time, and just wind up with a massive datastructure to store in memory. Unless that is not how it was done before, and the flattening is new and performance strong…

1 Like

I don’t know how it did it previously, but it’s how it does it now.

@zml likely could tell you more.

PEX’s inheritance calculation has been entirely redesigned for 2.x, so in theory it shouldn’t have the same performance issues. I think people have already started setting up long inheritances and it’s fine? Either way, there shouldn’t be a huge performance difference since PEX caches the results of lookups for a specific context.

I’d just use a LoadingCache.