Closed natfitz closed 6 years ago
The agent builders can be chained, simply add .asDecorator()
to the end after .transform()
and only install a single transformer. Every transformer has a large overhead and you should avoid piling them up.
Interesting...I was able to get a decent reduction in overhead with removing some duplication of transformers like so
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
return builder
.visit(Advice.to(HttpURLConnectionGetInputStreamAdvice.class)
.on(ElementMatchers.named("getInputStream")))
.visit(Advice.to(HttpURLConnectionConnectAdvice.class)
.on(ElementMatchers.named("connect")))
.visit(Advice.to(HttpURLConnectionGetOutputStreamAdvice.class)
.on(ElementMatchers.named("getOutputStream")));
}
So am I understanding correctly that the suggestion is to have one transformer that contains all of the .visit()
and I would reuse it across the agent builder like so
AgentBuilder agentBuilder =
new AgentBuilder.Default()
.ignore(none())
.type(named("javax.servlet.http.HttpServlet")).and(isPublic())
.transform(new UniversalTransformer(instrumentation))
.asDecorator()
.type(named("javax.servlet.RequestDispatcher"))
.transform(new UniversalTransformer(instrumentation))
.asDecorator()
Yes, doing so, Byte Buddy does not need to parse the byte code multiple times and can reuse a single serialization.
Thanks for the help, with the changes in place I'm seeing reduction of at least 50% on start up time of my small test apps.
Hi @raphw ,
i am not getting .asDecorator() as a method. I even checked this file. Can you please help me with if this is still supported?
It's the default now and you can use asTerminal() to get the previous behaviour in recent versions.
We are working on a Java agent to inject tracing information in various RPC libraries, and we have been getting reports that the agent is causing significant increase in startup times for larger applications. In some anecdotal cases start up used to be 30 seconds but is now 10 minutes with the agent installed.
The initialization of the transformers
Example of a transformer
From what we can tell each transformer adds a small bit of overhead but with us creating so many the time is adding up to be quite significant. Is there a way to accomplish this without scanning all of the classes for each transformer?