Open Electroid opened 3 years ago
I think this is a brilliant idea. In Minestom we are heavily bottlenecked by the networking side of things and being able to frame a packet once is a big advantage. Current solutions are to either attempt a translation and check for equality or traverse the entire tree and check for translatable components, both of which are far from perfect solutions.
I agree that this would be a much better solution, an EnumSet
containing a collection of flags would be a brilliant idea. Perhaps a flag for translations could go further and be split into vanilla vs. non-vanilla translations, or maybe just "this component has translations that exist in the translator" would go even further in making this a powerful tool.
Since a
Component
is immutable, during construction, we should store some "hints" about it and its children that are accessible inO(1)
time. For example, one of the most common algorithms is to traverse aComponent
tree and translate keys. If we provided a hint for whether the component contained a translatable in its tree, we could fail-fast during translation. This is also applicable for #114, since we can provide a hint if the component is already compacted.Is the tradeoff of faster time complexity for larger space complexity worth it? If it's done with an
EnumSet
orBitSet
, I think it's manageable. Components can have complex structures, and not everything has a translatable. This could considerably speed up translations.