Jump to content

[1.7.10] Is it possible to compile and load classes during mod initialization?


kauan99

Recommended Posts

I was wondering if I can use the compiler API to compile one of my mod's classes during one of the initialization events (pre, init, post) and then tell the class loader to load that class as one of my mod's.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

cool :). It would be harder and more vulnerable to erros to dynamically write the whole class via asm. it's possible, just not an approach I wish to take if I have a choice. Is there a way to add the compiler as a dependency (an external jar)? and if yes, will it take up memory after I'm done with it?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

I need it because the host environment where I will run this mod has low performance and already has a lot of mods. I would create the class at runtime in an attempt to optimize it, creating only what is necessary and marking everything I can as final to allow JIT optimizations. this may sound as pre-optimization, but it really isn't. the server is already having a bad performance. I have to do anything I can to maybe avoid making it worse.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

the class that holds my mod's items. My mod adds a lot of item sets (armor, trinkets (currently rings and necklace from baubles. I plan to write my own custom inventory to optimize trinkets later) and weapons (either swords or bows). every tool/armor material can be customized by the user via config file, every potion effect given by wearing the set. but because of this customizations, a lot of stuff can't be

final

, otherwise it would have to be hardcoded instead. I feel the JIT would do a better job if I was able to dynamically define that class. I'm also avoiding static stuff that I will need only during initialization, to allow the GC to be able to dispose of things as soon as they are out of scope.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

the fields are static. each field is only set once during preInit. The JIT probably can't optimize the fields because they are static and are not set during type construction. But it's ok. I'm just trying hard to squeeze every bit of performace optimization I can, because the server is already too slow as it is. It was a lot better when I ran Cauldron instead of pure Forge, but I couldn't make my event handling code work properly for Cauldron. Anyway, thanks for the code example, that may come in handy some other time.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.