bhaskar_narla has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using a jar file in Perl script using Inline::Java module. First I am initializing the beans and then getting a service bean. Using this service bean, I am executing a query to get the results(Java domain objects). The query execution is taking almost 10 seconds. After getting the results, I am constructing a hash with the required data. I am fetching this data by calling getter methods defined on each object in the result. But the issue is each getter call itself taking 350 milli seconds. I have thousands of objects in the result. So it is taking 20-25 minutes to construct the complete hash. Is there any way to reduce the time taken by each getter call ? or Is there any way through which I can convert the Java objects into hash directly ?
  • Comment on Performance Issue with Inline::Java module

Replies are listed 'Best First'.
Re: Performance Issue with Inline::Java module
by ikegami (Patriarch) on Nov 23, 2010 at 07:40 UTC

    There's a good chance that replacing 1000 slow calls with one would help. I don't see any way of building a Perl hash, but you can return a list (using a "[]" return value) from which you can build the hash.

    Using the above method, you'd still have to pass as many values as before. If that's the slow part, you could serialise the data for the hash into a single string on the Java side, then deserialise it on the Perl side. Then you only have one call, and only one value is exchanged between Java and Perl. This is of course far more complicated and error prone.

    No guarantees.

      Thanks, replacing n Java calls with 1 call sounds good.
Re: Performance Issue with Inline::Java module
by Anonymous Monk on Nov 23, 2010 at 06:36 UTC
    Is there any way to reduce the time taken by each getter call ?

    No. You're dealing with 2 independent virtual machines, and glue to connect them, and that is always going to be slow and memory hungry.

    or Is there any way through which I can convert the Java objects into hash directly ?

    Maybe theoretically (in the sense that anything is possible), but not in any practical way.

      If it is not possible with Inline::Java, is there any other way ?

        If it is not possible with Inline::Java, is there any other way ?

        No.

        Well, maybe if you're an expert c-programmer, know how to get netbeans objects from JVM, and know enough perl5 details to make perl hash using C, then maybe you can get something working .... and then you've reinvented Inline::Java :)

        More practical solution would be to try the simple things like ikegami suggests.

        I don't know much about netbeans, but it would be faster if you could eliminate the java middle man altogether and connect directly from perl (or c/c++/xs), but its likely quite a bit more work