A Clojure pipeline that reads 120 Excel files, cleans them and writes one CSV ran in 40 seconds as a native Windows executable, against 50 seconds as a standalone Java archive. The executable weighed 11 MB, the archive 88 MB, and only the archive needs a Java runtime on the user's machine.
The use case is common in data work without IT infrastructure: load a folder of Excel files, add a few database tables, filter, join, reshape, write the result back. R does this in a few lines, but installing and maintaining R on end users' machines, even the portable version, is where projects stall. The previous post delivered a model as a Go binary. Clojure offers the same end point, a single executable, with something Go lacks: a real REPL, where each step of a pipeline is evaluated and checked as it is written, as in an R session.
Smaller and faster once compiled
GraalVM's native-image compiles the standalone jar ahead of time into a Windows executable. On the Excel demo, that removed a fifth of the run time and seven-eighths of the size.
Part of the speed-up is start-up: a native image does not boot a Java virtual machine. A single run on one machine is an indication, not a benchmark.
The pipeline
The data-frame library is tablecloth, built on tech.ml.dataset. The demo finds every .xlsx in a folder, reads the relevant sheet of each, normalises the column names, drops rows without an ID, and concatenates the lot. pmap spreads the files over the processor's cores with no further code. The core, simplified (logging and error handling removed):
(defn load-and-clean-table [filepath]
(let [ds (load-table filepath)]
(-> ds
(tc/rename-columns (create-cols-clean-map ds))
(tc/drop-missing :tp_nr))))
(defn excel-worker [folder-path]
(let [tables (doall (pmap load-and-clean-table (fs/get-xlsx folder-path)))]
(tc/write! (apply tc/concat tables) (fs/set-filename "csv"))))Reading a database is two calls: next.jdbc runs the query, tc/dataset turns the result into a data frame. Because Clojure runs on the JVM, any Java library from Maven, such as a vendor's JDBC driver, is one line in project.clj.
The trade-off
Speed on large flat files is not Clojure's strength. In a quick test on a one-million-row CSV, tablecloth loaded the file about three times more slowly than R's data.table. Setting up GraalVM on Windows is also work: the native-image tool, the Visual Studio Build Tools, the Windows SDK and several environment variables. It is done once, by the developer, not by every user.
About the code
Code and build instructions: clojure_for_data_manipulation on GitHub. Size and run-time figures are from the repository's README: one run of the Excel demo on 120 files, standalone .jar built with lein uberjar against the .exe built from it with GraalVM native-image. The CSV comparison with data.table is the author's quick, unpublished test.