开发者

Slow calls to clojure proxy

开发者 https://www.devze.com 2023-01-31 05:57 出处:网络
I have an application in clojure mak开发者_Go百科ing heavy use of a Java framework called Vaadin. Vaadin uses several callbacks using the Java \"proxy\" feature of clojure. However, every time a proxy

I have an application in clojure mak开发者_Go百科ing heavy use of a Java framework called Vaadin. Vaadin uses several callbacks using the Java "proxy" feature of clojure. However, every time a proxy is called in a clojure function there is a significant delay (100s of milliseconds sometimes). Is there any way I can speed this up?


My understanding is that the new reify macro is faster than proxy. You can use it if you only need to implement a single interface.

For example, if you need to implement a java.awt.event.ActionListener you can use code like the following:

(import 'java.awt.event.ActionListener 'javax.swing.JButton)
(let [a-button (JButton. "Click Me")]
  (.addActionListener a-button
    (reify ActionListener
      (actionPerformed [this ev] (comment do something interesting)))))
0

精彩评论

暂无评论...
验证码 换一张
取 消