Right now my Lisp code runs roughly 50 slower than my Java code doing the same thing... Doesn't feel right...
- yavannadil, 2516 days ago
mocl does not currently optimize multi-dimensional arrays. If you can store the image with a single dimension (i*j in size), it will be much faster. Something like:
(deftype octet-vector () '(simple-array (unsigned-byte 8) (*)))
(deftype octet () '(unsigned-byte 8))
(defun foo (image)
(declare (type octet-vector image))
(let ((threshold #x7F))
(dotimes (i (length image))
(let ((current (aref image i)))
(declare (type octet current))
(setf (aref image i) (if (> threshold current) 1 0))))))
One other tip:
(make-array size :element-type '(unsigned-byte 8) :initial-element 0) will fill 0 very quickly, so then in the above code you would only need to set elements for the 1 case but not the 0 case. (This doesn't currently work for any other :initial-element besides 0, however).
Let me know if that helps.
Wes
- Wukix, 2516 days ago
I was mistaken - with multi-dimensional arrays Mocl was 1000 (not 50) times slower than Java. With vectors, elapsed time dropped from 7000 milliseconds to 350 milliseconds. It's still 50 times slower than Java, but it's useable.
Will try with an older device and on IPhone...
- yavannadil, 2512 days ago
On HTC Desire S Java works as slow as Mocl on LG Nexus 5 with vectors, and Mocl on HTC with vectors as multi-dimensional Mocl on LG...
It seems I'll have to adapt my testsuite to Java anyway :(
- yavannadil, 2512 days ago
It's possible if you are working with large arrays that mocl is having to garbage collect too often, and expanding the heap size would help. Take a look in mocl_config.h for some options.
Also, please make sure DEBUG is not defined during build (mocl performance is very sensitive to this). Under Android see http://stackoverflow.com/questions/6589369/debug-vs-release-builds-in-the-android-ndk. Under Xcode it is simpler: just set the Debug/Release build configuration to 'Release'.
Last but not least, if you can provide some simple performance test cases that I can run so we can compare apples to apples in milliseconds, I will try to find a solution for you. Let me know.
Wes
- Wukix, 2512 days ago
Added APP_OPTIM := release
to Application.mk, with no noticeable effect...
Wrote to you to engineering@wukix.com
Thank you for your help!
- yavannadil, 2511 days ago
With your improvements, Lisp code now runs, on Nexus 5, twice as fast as Java! Thanks a lot!