<div dir="ltr"><div>Here's an example of fast reading in ABCL. The implementation of certain array types use java.nio buffers, which can be directly read into via the java.nio functions.</div><div><br></div><div><span style="font-family:monospace">(defun test-read (path)</span></div><span style="font-family:monospace">  (let* ((f (new 'RandomAccessFile (namestring (truename path)) "r"))<br>         (channel (#"getChannel" f))<br>         (array (make-array (* 16 1024 1024) :element-type '(unsigned-byte 8)))<br>         (buffer (get-java-field array "elements" t)))<br>    (time (loop for count = (#"read" channel buffer)<br>                until (eql count -1)<br>                sum count<br>                do (#"position" buffer 0)<br></span><div><span style="font-family:monospace">                ))))</span></div><div><br></div><div>On my machine, for a 5G file, the SBCL code in an earlier post takes 2.4 seconds. This code takes 1.4 sec. It's fastest if I use 2M buffers - 1.1 seconds. SBCL is also marginally faster with smaller buffer sizes.<br></div><div><br></div><div>In the ABCL source code the files "SimpleArray_*.java" are the implementations of the nio buffer backed array types. See make_array.java where the specific type of underlying array is chosen. There is a global switch for array allocation choosing either direct allocation or nio-buffers, with the default being nio buffers.</div><div><br></div><div>(get-java-field 'java$buffers "active" t)</div><div>-> #<org.armedbear.lisp.Java$Buffers$AllocationPolicy NIO {432E958E}> </div><div><br></div><div>I haven't looked into the :element-type 'character case. <br></div><div><br></div><div>Maybe someone who is familiar with the ABCL stream implementation is interested in writing a fast path for read-sequence that uses the nio calls? If so, shout. Otherwise I'll keep it on my procrastinate-by-hacking-abcl list.<br></div><div><br></div><div>Alan<br></div><div><br></div></div>