Skip to content

Java interface using closure implementaion is slower than mixin implementation #1401

Description

@colinsurprenant

I benchmarked & profiled the different Java interface implementation strategies and found out that using a block/closure interface implementation is slower than using a class & mixin implementation.

As we can see in the profiling:

---------------------------------------------------------------------------------------------------------
                      70.23       50.56       19.67                   1/1  Object#java_sort_with_closure_comparator
    99%     71%       70.23       50.56       19.67                     1  Java::JavaUtil::Collections.sort
                      19.67       15.25        4.42     82562064/82562064  #<Class:0x6e36a818>#method_missing
---------------------------------------------------------------------------------------------------------
                      19.67       15.25        4.42     82562064/82562064  Java::JavaUtil::Collections.sort
    28%     21%       19.67       15.25        4.42              82562064  #<Class:0x6e36a818>#method_missing
                       4.42        4.42        0.00     82562064/82562064  String#<=>
---------------------------------------------------------------------------------------------------------
                       4.42        4.42        0.00     82562064/82562064  #<Class:0x6e36a818>#method_missing
     6%      6%        4.42        4.42        0.00              82562064  String#<=>

the problem lies in the indirection via #method_missing to call the closure, implemented in core/src/main/java/org/jruby/javasupport/JavaUtil.java. There is probably a more efficient way to call the closure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions