mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-20 21:10:05 +00:00

This is the second time I've rewritten our class generation in a little over a month. Oh dear! Back in d562a051c7b3b114d6821c4a3a5d9d025a782f0a we started using method handles inside our generated ASM, effectively replacing a direct call with .invokeExact on a constant method handle. This goes one step further and removes our ASM entirely, building up a MethodHandle that checks arguments and then wraps the return value. Rather than generating a class, we just return a new LuaFunction instance that invokeExacts the method handle. This is definitely slower than what we had before, but in the order of 8ns vs 12ns (in the worst case, sometimes they're much more comparable), so I'm not too worried in practice. However, generation of the actual method is now a bit faster. I've not done any proper benchmarking, but it's about 20-30% faster. This also gives us a bit more flexibility in the future, for instance uisng bound MethodHandles in generation (e.g. for instance methods on GenericSources). Not something I'm planning on doing right now, but is an option.