Capability Fix - Performance Optimization for Capabilities
This mod addresses one of the key performance issues in version 1.20.1 Forge/NeoForge - inefficient capability searching on entities. The standard implementation in this version iterates through all capability providers for each entity, which becomes extremely slow when there are many mods adding such providers.
The solution offered by this mod involves caching for specific capabilities. The mod creates a capability cache for each entity and stores data during the first access. For capabilities included in the whitelist, subsequent requests will be processed directly from the cache, bypassing the lengthy search process through all providers.
This approach is safe only for capabilities that remain available on entities from the first access and are never removed or reattached later. A typical example is the Curios API capability. By default, the mod operates based on a whitelist, but you can take the risk and apply it to all capabilities through configuration settings.
It is recommended to use this mod only after confirming with spark that capability searching on entities takes at least 4% of the server's total time (mspt). When fully deployed, the mod can reduce capability search costs by 75%, as tested on a modpack where initial costs were 8% of server mspt.
Correct usage procedure:
- After the game has been running for some time, execute the command
/capabilityfix gather_others
. It will show how many times each capability was requested. - Open the latest.log file, find the corresponding chat message, and copy the capability identifier into the configuration file
capabilityfix-common.toml
. - In the game, execute
/capabilityfix reload_config
to apply changes to the whitelist. - Test the functionality related to this capability for any errors. If problems are found, remove it from the whitelist.