-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
[ji] lazy loading of Java (proxy) class extensions #5161
Conversation
No prob, will review. Have you managed to measure anything yet? |
quick test of
... gets us around 5% on my machine |
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 static reference needs to be fixed, and the naming is problematic, but otherwise this seems ok. I worry a bit about races but the logic that sets up the proxy class should be safe currently. Will request review from @enebo.
} | ||
|
||
@JRubyModule(name = "Java::JavaLang::Iterable", include = "Enumerable") | ||
public static class Iterable { | ||
|
||
static RubyModule define(final Ruby runtime) { | ||
final RubyModule Iterable = Java.getProxyClass(runtime, java.lang.Iterable.class); | ||
static RubyModule define(final Ruby runtime, final RubyModule Iterable) { |
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.
Could we use a different name for these? I find it extremely confusing when I look at the code and I see "Iterable" meaning two different things.
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.
Note that at this point in the code, Iterable now means three different things: the inner class, the variable, and (to me at a glance) the actual Java Iterable class. It's quite confusing.
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.
Same comment applies to all other such names below. I understand that it might look a bit nicer to some, but this flies against typical Java local variable naming convention.
It's somewhat confusing that the extension classes have the same names as the Java class they extend, but that seems like less of an issue to me than the local variables having yet again the same name.
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.
okay, will take a look into that
|
||
private static final boolean IMMEDIATE = false; | ||
|
||
private static final JavaExtensions INSTANCE = new JavaExtensions(); |
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.
This should not be static; a better place would be for it to live on the javasupport Java instance attached to the runtime.
It is weak on the value, but it also anchors a class as its key. The classes we currently extend are system-level classes, but this may be used in the future for classes loaded as part of JRuby or within extensions (e.g. jruby-openssl) that load into their own classloaders, and this reference will prevent them from being collected.
It also is not compatible with multiple JRuby instances in the same JVM, since only the first one will register (and eventually apply) an extension. The others will race to insert the extension or remove it when applying that extension.
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.
Oh somehow my review used an older version that was still static. I see you have fixed that, thanks!
✔️
exactly - its plugged in right around proxy-class initialization which is already race condition tuned (some tests are in place) |
assert previous == null; | ||
} | ||
|
||
public static void define(final Class javaClass, final RubyModule proxyClass) { |
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.
Seems like runtime could be a parameter here to match put().
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.
It also seems to line up more with Iterable stuff below which also have runtime.
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.
Seems reasonable to me. I guess only fear is proxy class initialization concurrency, but that has not actually changed at all in this PR so seems fine.
3325389
to
ab086b7
Compare
also ... we could safely add more extensions now and do not have to worry much about bloating load times
did not run any numbers yet, but hopefully we do not do much JI internally on
gem list
,rake
etc