SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.41k stars 194 forks source link

Inability to get all classes targetted by mixin #661

Open 0xJoeMama opened 6 months ago

0xJoeMama commented 6 months ago

While developing a mod loader as a side project for fun, I run into the following issue: Mixins requires a class node, which means that all classes passed through to it, need to be parsed at runtime. After some performance testing, I found out that that increases classloading times by a large enough amount to have me concerned(an average of 0.5s on my machine, when starting up minecraft through the loader). So I thought: "That's no big deal. I'll just ask mixin what classes it targets, so I may only parse them if required". However, after looking around, I can't seem to find any public API in mixin, that allows getting the classes targetted by mixin, or whether a specific class is a mixin target. Looking at the MixinConfig class, the required methods do exist, however they are package private.

And so I'd like to know: is there any way to do that? If not could a feature like this be implemented?

LlamaLad7 commented 6 months ago

No, Mixin only parses the classnode if it needs to modify it. You never need to parse the node yourself. Look at fabric's implementation.

0xJoeMama commented 6 months ago

That doesn't seem to be the case. Look here: https://github.com/SpongePowered/Mixin/blob/41a68854f6e63e8ec6d38e7d7612230d7f73a9bc/src/main/java/org/spongepowered/asm/transformers/TreeTransformer.java#L54

LlamaLad7 commented 6 months ago

You don't interact with that, you interact with https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/IMixinTransformer.java

0xJoeMama commented 6 months ago

Yes but I do use IMixinTransformer. However the exposed methods, either take in a ClassNode or take in a byte array, which is then parsed into a ClassNode. Checking the transformClassBytes method in MixinTransformer, leads to a call to transformClass which in turn calls readClass which parses the ClassNode. Unless I am missing something.

https://github.com/SpongePowered/Mixin/blob/41a68854f6e63e8ec6d38e7d7612230d7f73a9bc/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java#L191

https://github.com/SpongePowered/Mixin/blob/41a68854f6e63e8ec6d38e7d7612230d7f73a9bc/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java#L232

0xJoeMama commented 6 months ago

There has been no response on this for a week. Anything new?

Geolykt commented 6 months ago

I'd not be worried - it is quite usual for issues to go silent in an issue tracker. And you shouldn't really expect a rather fast development cycle for Mixin so it might take a long time till it gets resolved.