clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.06k stars 69 forks source link

How to get native python-like performance for this snippet. #114

Closed zendevil closed 3 years ago

zendevil commented 4 years ago

pytorch snippet:

(require-python 'torch)

(time
 (dotimes [n 500000]
   (py. torch/nn Linear 5 3)))

"Elapsed time: 65831.100093 msecs"

start_time = time.time()
for i in range(500000):
    torch.nn.Linear(5, 3)
print("time", (time.time() - start_time)*1000)

time 21006.22010231018

  1. The clojure code is about 4.4 times slower, in general about 3-7x whether the operation is repeated 5000, 50000 or 500000 times. Is there a way to get at the very least a constant overhead with clojure?

  2. The repl sometimes closes unexpectedly. #113

cnuernber commented 4 years ago

Perhaps meditate on this comment: https://github.com/clj-python/libpython-clj/issues/112#issuecomment-671891733

cnuernber commented 3 years ago

I don't think this is fixable with our current level of tech. The JDK-16 pathway is going to be a bit faster but we can't call into python as fast as python can call into python; there is just too much to bridge there.