Hello,
That is an interesting blog post. I am not a clojure specialist, but if I
was to try to change your program to get towards C-like speed (or better), I
would :

- Use java arrays for memory. You don't seem to use the vectors in a
persistent way, and there does not seem to be easy parallelization of the
vm. That's less elegant but probably quicker. I wouldn't say the same thing
if there were possible ways of using persistency later on in the problem.

- Most criticaly, try to use JVM's very good JIT. If it is possible. I
haven't looked to the OVM code precisely.
  If you replace :

(defn make-add
 [#^Integer r1 #^Integer r2 #^Integer pc]
 (fn [machine-state]
 (update-in machine-state [:data] ...)

by :

(defmacro make-add
 [r1 r2 pc-var]

 `(let [pc# (+ 1 pc-var)  (update-in machine-state ...)...)

And instead of reading the instruction and storing them in a vector
you create a term:

program-term =

   `(fn [input-array output-array memory]

          (do ~...@list-of-instructions)

Then you (eval program-term) (once only) at run time, or macro expand
it at compile time (if you have the right to use the binary at compile
time.)

This way, the code should be very fast, once the JIT starts. You can
hope better speed than C, because once compiled, you remove the
decoding phase of the opcode the C program has to do on each run.
Somehow you used clojure to translate OVM bytecode to - hopefully good
- JVM bytecode, that the JVM is very good at executing.

Can a clojure expert confirms wether it would work or not?

Best regards,

Nicolas.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to