-
Notifications
You must be signed in to change notification settings - Fork 989
Remove trivial uses of Guava from agent. #2360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -489,8 +489,16 @@ public void onComplete( | |||
@Override | |||
public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) { | |||
// filter out our agent classes and injected helper classes | |||
return Iterables.transform( | |||
delegate.resolve(instrumentation), i -> Iterables.filter(i, c -> !isIgnored(c))); | |||
return () -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope you do understand this and tested it :) Looks like black magic to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Stream (single use) vs Iterable (multiuse) dilemma is always annoying. The safe way to convert a Stream into an Iterable is creating a Lambda that initializes the Stream and returns the iterator, which is what an Iterable is.
The alternative is to collect(toList) each time which I'm ok with but I don't know this part well enough to know if the extra allocations would be problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think naming the Iterable <-> Stream transformations makes it (a bit) easier to read:
public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) {
// filter out our agent classes and injected helper classes
return iterableOf(
streamOf(delegate.resolve(instrumentation))
.map(classes -> iterableOf(streamOf(classes).filter(c -> !isIgnored(c)))));
}
private static <E> Stream<E> streamOf(Iterable<E> iterable) {
return StreamSupport.stream(iterable.spliterator(), false);
}
private static <E> Iterable<E> iterableOf(Stream<E> stream) {
return stream::iterator;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately stream:: iterator
isn't a real Iterable since it can't be replayed, so toIterable
would need to accept Supplier<Stream>
. Not sure if that ends up better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried, how is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately
stream:: iterator
isn't a real Iterable since it can't be replayed
😭
ok, how about
public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) {
// filter out our agent classes and injected helper classes
return () -> streamOf(delegate.resolve(instrumentation)).map(this::filterClasses).iterator();
}
private Iterable<Class<?>> filterClasses(Iterable<Class<?>> classes) {
return () -> streamOf(classes).filter(c -> !isIgnored(c)).iterator();
}
private static <T> Stream<T> streamOf(Iterable<T> iterable) {
return StreamSupport.stream(iterable.spliterator(), false);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure seems good
...ooling/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/matcher/ReferenceMatcher.java
Show resolved
Hide resolved
@@ -489,8 +489,16 @@ public void onComplete( | |||
@Override | |||
public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) { | |||
// filter out our agent classes and injected helper classes | |||
return Iterables.transform( | |||
delegate.resolve(instrumentation), i -> Iterables.filter(i, c -> !isIgnored(c))); | |||
return () -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think naming the Iterable <-> Stream transformations makes it (a bit) easier to read:
public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) {
// filter out our agent classes and injected helper classes
return iterableOf(
streamOf(delegate.resolve(instrumentation))
.map(classes -> iterableOf(streamOf(classes).filter(c -> !isIgnored(c)))));
}
private static <E> Stream<E> streamOf(Iterable<E> iterable) {
return StreamSupport.stream(iterable.spliterator(), false);
}
private static <E> Iterable<E> iterableOf(Stream<E> stream) {
return stream::iterator;
}
The only remaining usage in the agent is caching, and there is usage at compile time by muzzle of the graph library and some test usage. So we'll be able to replace the caching with caffeine for a bit smaller distribution size and probably better cache performance.