MinecraftForge / AccessTransformers

Antlr4 definition for MCP / Forge Access Transformers
GNU Lesser General Public License v2.1
14 stars 12 forks source link

Speed up AccessTransformerList #17

Closed ichttt closed 7 months ago

ichttt commented 2 years ago

As said in #16 , this method is quite hot as it gets called on runtime for every class loaded. The average time spend in this method before this patch on a miss (which should be most of the time) is ~10 microseconds, which is actually not too bad, but it can be easily improved. This patch reduces the time spend in this method in any case to a few nanoseconds while keeping the load time roughly the same.

I guess it will not actually be noticible in most real-world cases, after doing some math I figured that it will probably save less than one second in total even in large modpacks, but I'll open this PR anyways as I already wrote the code.

Actual benchmark results for those interested (Comparable to the numbers in #16, same PC):

"Benchmark","Mode","Threads","Samples","Score","Score Error (99,9%)","Unit"
"net.minecraftforge.accesstransformer.benchmarks.AccessTransformerListBenchmark.testATLoad","avgt",1,4,"3759,676171","3315,141406","us/op"
"net.minecraftforge.accesstransformer.benchmarks.AccessTransformerListBenchmark.testAtContainsHit","avgt",1,4,"0,082784","0,004119","us/op"
"net.minecraftforge.accesstransformer.benchmarks.AccessTransformerListBenchmark.testAtContainsMiss","avgt",1,4,"0,026256","0,003513","us/op"

The second commit reduces the time to build the AT list ever so slightly, results after that:

"Benchmark","Mode","Threads","Samples","Score","Score Error (99,9%)","Unit"
"net.minecraftforge.accesstransformer.benchmarks.AccessTransformerListBenchmark.testATLoad","avgt",1,2,"3510,183963",NaN,"us/op"
"net.minecraftforge.accesstransformer.benchmarks.AccessTransformerListBenchmark.testAtContainsHit","avgt",1,2,"0,088348",NaN,"us/op"
"net.minecraftforge.accesstransformer.benchmarks.AccessTransformerListBenchmark.testAtContainsMiss","avgt",1,2,"0,029233",NaN,"us/op"