does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
I use clojure more and more in production.
To use it even more there, I need to be certain
about the answer of the following question.

My experiments lead me to the conjecture, that
the answer is yes.
But a proof can only be given by someone,
who is familiar with clojure's implementation of which I
have no clue.

Thanks for your help !:

The question is concerned with calling clojure from Java.

I have a bunch of clojure stuff, which I compiled to byte
code with the techniques described at http://clojure.org/compilation
I made an archive A of the result.
I have Java code, that uses things from A.
Now: The first time something from A is called, there is a little delay.
Afterwards there is no delay.
Is it true, that, in a given JVM, only the very first call to something in
A, will cause a delay ?


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
This has nothing to do directly with Clojure :)

The JVM needs to load the class(es) involved. 
It involves obtaining the class files from disk or cache if lucky (an already
opened jar file ?).
Then some wiring has to be done to insure that the references needed from the
class(es) are met,
After these steps then optimizations can kick in so future calls are optimized 
if
necessary.

The Clojure merely spits out classes like the Java compiler does.

Luc


 I use clojure more and more in production.
 To use it even more there, I need to be certain
 about the answer of the following question.
 
 My experiments lead me to the conjecture, that
 the answer is yes.
 But a proof can only be given by someone,
 who is familiar with clojure's implementation of which I
 have no clue.
 
 Thanks for your help !:
 
 The question is concerned with calling clojure from Java.
 
 I have a bunch of clojure stuff, which I compiled to byte
 code with the techniques described at http://clojure.org/compilation
 I made an archive A of the result.
 I have Java code, that uses things from A.
 Now: The first time something from A is called, there is a little delay.
 Afterwards there is no delay.
 Is it true, that, in a given JVM, only the very first call to something in
 A, will cause a delay ?
 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
Thank you, for your answer.

It doesn't convince me, though.

I am well aware of the class loading mechanism of the JVM.
But if I compile against, say guava-12.0.jar (beautiful stuff by the way),
and use those classes at runtime, there is no delay in using them
whatsoever.

At least not a delay of nearly a second on my machine, the first time
I use bytecode generated by clojure.

I am quite sure, that the bytecode generated by clojure, initializes some 
sort
of Runtime for itself, the first time it is called.

My question is, does this happen more than once ?

Furthermore clojure does not spit out classes. It spits out bytecode.

Heinz.




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
Ah, do you compile your Clojure code to Java prior to using it (AOT 
compilation) ?
If not, you must add the clojure compilation time to spit out the class(es) 
byte code.

Here we deliver AOTed components so there's no compilation overhead,
we do this for other reasons than this very small overhead.

Of course this will occur only once.

Luc


 Thank you, for your answer.
 
 It doesn't convince me, though.
 
 I am well aware of the class loading mechanism of the JVM.
 But if I compile against, say guava-12.0.jar (beautiful stuff by the way),
 and use those classes at runtime, there is no delay in using them
 whatsoever.
 
 At least not a delay of nearly a second on my machine, the first time
 I use bytecode generated by clojure.
 
 I am quite sure, that the bytecode generated by clojure, initializes some 
 sort
 of Runtime for itself, the first time it is called.
 
 My question is, does this happen more than once ?
 
 Furthermore clojure does not spit out classes. It spits out bytecode.
 
 Heinz.
 
 
 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
Yes, I do compile my clojure code ahead of time (AOT) to byte code.

Does that mean, that your, ahead of time compiled clojure code,
has no noticeable delay, when you first call it ?

If in the middle of the lifetime of an app, this delay happens,
i can not consider it small, if 1 requests are waiting
to be served.

Heinz.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
Compared to Java, not noticeable if any. We run our app in production on 
cluster of
small computers.
We replaced component written mostly in Java by Clojure equivalents without
any degradation in service time. We used clojure from java a number of times
using Java callable interfaces generated in Clojure (gen-class). Now it's the 
other way
around.

They're might be a bigger overhead if you call your code through the RT class 
instead
of using generated APIs.

Luc

 Yes, I do compile my clojure code ahead of time (AOT) to byte code.
 
 Does that mean, that your, ahead of time compiled clojure code,
 has no noticeable delay, when you first call it ?
 
 If in the middle of the lifetime of an app, this delay happens,
 i can not consider it small, if 1 requests are waiting
 to be served.
 
 Heinz.
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh


 Hm. I do have the feeling, that we do not understand each other.

Code is always unambigous.
I give an example, and give my question another run.

(ns p.x
 (:gen-class
  :methods [ ^{:static true} [f [] String] ]))

(defn -f [] hello, world)

Fire up a REPL, make sure, p/x.clj is in your classpath, as well as
classes (the default value of *compile-path*) and do

user= (compile p.x)

Go out of the repl, cd into classes and do a

$ jar cf a.jar *

package e;

import p.x;

public final class E {
   public static void main(String[] args) {
for (int i = 0; i  100; ++i) {
  System.out.println(x.f());
}
}

Fire up the java compiler (javac) on that Java source code, making sure, 
that
he can find a.jar.

Now run E with the java launcher, making sure than a.jar and clojure.jar
are in its classpath.
Something like so:

$ java -cp a.jar:clojure.jar:./classes  e.E

Observation:
---
The first hello world, takes a second or so to appear.
The 99 following are coming super fast, like always.

Question:
--
1. Am I doing something wrong or disadvantegous, and that
   is an explanation for the delay ?
2. If not, does this delay happen only once in a given JVM ?

Thanks for your help.

Heinz.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
The following makes it clearer:

package e;

 import p.x;

 public final class E {
public static void main(String[] args) {

   System.out.println(before); 

 for (int i = 0; i  100; ++i) {
   System.out.println(x.f());
 }
 }


Now: After launching, the string `before' gets printed (JVM up),
and *then* there is delay, before the first `hello, world'.

Jetzt aber. 

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
It's the time to get all the related classes loaded needed to support the 
Clojure
code and yes it's a one time cost. The first reference to x gets this triggered.

Luc


 The following makes it clearer:
 
 package e;
 
  import p.x;
 
  public final class E {
 public static void main(String[] args) {
 
System.out.println(before); 
 
  for (int i = 0; i  100; ++i) {
System.out.println(x.f());
  }
  }
 
 
 Now: After launching, the string `before' gets printed (JVM up),
 and *then* there is delay, before the first `hello, world'.
 
 Jetzt aber. 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Stuart Sierra
Yes, Clojure has a runtime which is initialized the first time you call 
any Clojure code. 

The initialization never happens more than once.

-S

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
Ah, cool !
Thank you very much for this insider knowledge, Mr. Sierra !!!

Great.
That means more clojure in production.
Hurrah !!!

Thanks again.

Heinz.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en