Automatic class splitting
rahulmutt opened this issue · 3 comments
When you have really large source files (2K+ lines), there's a chance that the generated class will be so huge that the constant pool size will exceed the 65,535 size limit. The compiler should change its code generation to avoid such problem - perhaps by shifting static methods definitions to individual classes instead of putting all the implementations into the Module class.
I've tried the mentioned suggestion and it made very little difference for the particular example I was working on. It turns out that the more general solution to this problem is to distribute constants more deeply in the generated classes. What's happening is that all the classes are being initialized inside the module class itself when they can be instantiated in the required closures that are demanded by the user.
By distributing class constants this way, we avoid hitting the classfile limits and avoid having to do workaround patches in packages like pandoc
.
Would it fix errors with too big methods?
Nope, which is why this is a separate issue. Overflowing the constant pool is a serious problem since the entire class file is considered invalid and will cause issues with tools like Proguard. Overflowing the bytecode limit is not as much of a problem - the bytecode size can be specified in a Word32
so the classfile is "valid" but the method itself will fail verification when called.