-
-
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
moving Ruby Java extensions into native #3802
Conversation
there's also some more work on top of this where Ruby <-> Java collision methods have a ruby_xxx name |
@kares I have two comments on this PR.
|
I think if we provide some yard docs (using the old .rb parts) for these it should sell well :) also more refactoring will be easier and it also opens up a clean path for potential lazy ext (when the Java proxy class gets first used in Ruby-land) loading if at some point we want to.
|
added commits dealing with Ruby vs Java naming collisions + the old .rb parts are loadable without harm. |
6eda76f
to
1f4445f
Compare
... and JI doc is coming along nicely: http://kares.org/jruby-ji-doc/Java/java/util/List.html ... still things to do. |
…eError`s previously it was sometimes ClassCastException, TypeError (attempted coercion)
... and not just for speed (most List extensions also missed specs) : - List [] and []= were improved to properly work like with a Ruby Array - detecting random-acess List for faster iteration - backward List iteration on rindex - for non random access using listIterator - Collection +/- will need more work as currently dup doesn't clone java objects
…loneable contract ... will work with most Java collection types as they provide a public clone method this also makes java.util.Collection's (previous) +/- additions actually work nicely !
…a clone method ... we can do so if we're able to allocate a new instance of the same class
... prev only clone worked but without Ruby's semantics for cloning singleton class
…control Java's Matcher now aligned with Ruby's MatchData (including named groups)
(Java 7 only due sort method collision on Java 8)
…ava.util.Map users will be able to do use ruby versions with a simple alias on concrete types e.g. `java.util.HashMap.class_eval { alias merge ruby_merge }` resolves #1249
…andle potential collision) e.g. java.util.LinkedList provides getFirst/getLast thus previously behaviour was : ``` java.util.ArrayList.new.first # nil java.util.LinkedList.new.first # throwing NoSuchElementException # will now behave consistent in Ruby-land with : java.util.LinkedList.class_eval { alias last ruby_last; alias first ruby_first } ```
…when it conflicts ... e.g. this would happen on java.util.Deque due having a getFirst method prescribed
… is a new helper)
just out of interest I checked memory usage before and after, there's a small decrease before ~ 17,5M :
after ~ 15,5M :
|
It's a lot to review but the move looks good, and it comes with a lot of edge case fixes and specs. 👍 |
basically all of the java/java_ext.rb pieces such as
java.util.rb
makes JRuby perform better (up to 4x) with a simple
java.util.ArrayList
script ... will probably improve further after more warmup.most of the time we do not need the full dynamic nature when extending behaviour of Java types e.g.
java.util.List#sort
using a Comparator implemented in Ruby (lot of "unnecessary" Java<->Ruby conversion) on eachcompareTo
improves #1401 performance **~ 2x**'old' .rb parts are loadable (without harm) and will be used for yard doc generation.
likely users do not use (know of) the provided Ruby extensions (which might change as we provide JI doc) much since I've run into several issues with non-working bits (e.g.
java.util.regex.Matcher
methods failing) or half-baked methods (e.g.java.util.List
's[] and
[]=compared to
Array`'s) - most of them are actually easier to manage/reason in Java. also most of the extensions are now covered with specs.there's also some new features along the way such as
dup
now working for Java arrays and collection types (on 1.7/9.0collection.dup
silently returns the same instance),dig
for lists, uniformly returning Enumerator oneach
without block and more mentioned bellow.further all collision methods (e.g. Java 8's
sort
) now have a ruby_xxx name as well so that users can easily "force" Ruby functionality on types e.g.java.util.ArrayList.class_eval { alias sort ruby_sort }
.CHANGELOG
NOTE: as previously only works on Java 7 as there's a sort collision with Java 8
removal should be more effective across different kinds of list implementations
(except internal impl classes such as ones returned from java.util.Collections factories)
java.util.ArrayList.class_eval { alias sort ruby_sort }
will make all array listssort
the Ruby way while the instance is being used in Ruby scripts.