Я использую метод «Совет». Когда я занимаюсь установкой точек сцепки, это занимает много времени. В ходе отладки я обнаружил, что следующая функция занимает много времени. Основной причиной должен быть этот цикл for-for. В типах около 27 тыс. классов. Более того, я выполнил метод installOn около 40 раз, что заняло слишком много времени.
Есть ли хороший способ оптимизации?
Вот часть кода.
Код: Выделить всё
private final AgentBuilder commonAgentBuilder = new AgentBuilder.Default()
.disableClassFormatChanges()
.ignore(ElementMatchers.none())
.ignore(ElementMatchers.nameStartsWith(ignorePackagesArray[0]))
.ignore(ElementMatchers.nameStartsWith(ignorePackagesArray[1]))
.with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE);
for (AdviceInfo advice : adviceInfo) {
AgentBuilder.Transformer transformer;
ResettableClassFileTransformer resetAgentBuilder;
transformer = new Transformer() {
@Override
public Builder transform(Builder builder, TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) {
return builder
.visit(net.bytebuddy.asm.Advice.to(MethodInterceptors.class)
.on(methodMatcher));
}
};
resetAgentBuilder = commonAgentBuilder
.type(classMatcher)
.transform(transformer)
.installOn(instrumentation);
}
Код: Выделить всё
net.bytebuddy.agent.builder.AgentBuilder.RedefinitionStrategy#applyКод: Выделить всё
for (Iterable type : types) { // types has 27k classes
if (...) {
continue;
}
collector.consider(type, DISPATCHER.isModifiableClass(instrumentation, type) || ClassFileVersion.ofThisVm(ClassFileVersion.JAVA_V5).isAtMost(ClassFileVersion.JAVA_V5));
}
batch = collector.apply(instrumentation, redefinitionBatchAllocator, redefinitionListener, batch);
}
Код: Выделить всё
for (Advice advice : adviceMap.values()) {
advice.getResetTransformer().reset(instrumentation, AgentBuilder.RedefinitionStrategy.RETRANSFORMATION);
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... sform-time
Мобильная версия