If you’re using ECL and a suitable C or C++ compiler is available, it’s recommended to set CFFI-SYS:*CFFI-ECL-METHOD* to :C/C++ before compiling cl-duckdb (especially for running benchmarks). This way ECL can compile FFI code as C/C++ statements and doesn’t need to rely on libffi, resulting in significantly better runtime performance. The other supported implementations (SBCL & CCL) only use libffi for passing C structs as values, so this isn’t much of an issue.
This can be enabled automatically using environment variables:
# Use C/C++ CFFI ECL method:
export CL_DUCKDB_USE_SFFI=t
# Optionally extend the search path of the linker:
export CL_DUCKDB_LIBRARY_PATH="/my/path/to/DuckDB/library/"
Alternatively the following can be used instead:
;; Tell the linker to link with DuckDB:
(setf compiler:*user-linker-libs* "-lduckdb")
;; CFFI needs to be loaded first:
(ql:quickload :cffi)
;; Set the CFFI ECL method:
(setf cffi-sys:*cffi-ecl-method* :c/c++)
;; Finally load cl-duckdb:
(ql:quickload :duckdb)
If you’ve loaded cl-duckdb before, you might need to delete the .fas files for it from the compiler cache (normally located in ~/.cache/common-lisp/) for this to take effect. Otherwise you might run into errors during compilation.