Closed dre4merp closed 1 month ago
You should concatenate the agent builder and only install it a single time after the loop. The transformations are additive by default.
Do u mean code like this?
for (AdviceInfo advice : adviceInfo) {
transformer = new Transformer() {...};
commonAgentBuilder
.type(classMatcher)
.transform(transformer)
}
resetAgentBuilder = commonAgentBuilder.installOn(instrumentation);
I tried it, it works but not obvious. Mainly I want to minimize the impact of too many classes (types). What should I do? Would it be more efficient to have the builder ignore more classes?
The fewer classes are transformed, the better. But retransforming is in itself expensive, so this reduces iterations by a lot.
My purpose is to hook some functions to implement monitoring. There are about 40 hook points. I am using the Advice method. When I do the installation of the hitch points, it takes a long time. Through debugging I found that the following function takes a long time. The main reason should be this for-for loop. There are about 27k classes in types. Moreover, I executed the installOn method about 40 times, which took too much time.
Is there a good way to optimize ?
Here is part of code.
Here is the function which takes long time.
net.bytebuddy.agent.builder.AgentBuilder.RedefinitionStrategy#apply
And the same to