Repository navigation
Call the C API v2 with the Foreign Function and Memory API on Java 22+ - #1018
Draft
Robinho-MR wants to merge 15 commits into
Draft
Robinho-MR wants to merge 15 commits into
Robinho-MR wants to merge 15 commits into
Conversation
…nerated native entry points
Member
|
CC @staticlibs this was an idea from Hannes, see also https://lemire.me/blog/2026/01/17/a-new-way-to-call-c-from-java-how-fast-is-it/ |
Member
|
@Mytherin Thanks for the details! Yes, absolutely, I was talking about this with Hannes quite a while ago, in 2025, - the FFM layer in the driver is highly welcome! Just the JDK 8 compatibility part is tricky, I need to look closer how it is done here and what the new generators are doing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calls the C API v2 directly from Java with the Foreign Function and Memory API (
java.lang.foreign), without JNI, on Java 22 and later. It is stacked on #1017 (the commits of that PR are included here, the last four are new). Older JDKs keep using the JNI bindings from the same jar.Details
DuckDBBindingsandDuckDBLibraryhave a Java 22 version insrc/main/java22that is packed intoMETA-INF/versions/22of the jars (Multi-Release: true). The 228 native entry points are implemented in Java on top of 212 downcall handles (Capi.java, generated byscripts/gen_ffm_native.pyfromduckdb_v2.h). Handles are passed around as before (zero-length directByteBuffers holding the pointer).duckdb_v2_*functions are exported from the library (previously 620),scripts/update_exports.pyregenerates the.map/.exp/.deflists.JAVA22_HOME. Without one the jars are built without them (JNI only), so building on JDK 8 is unchanged.Testing (Linux arm64, JDK 25 with FFM and JDK 21 with JNI, from the built
duckdb_jdbc.jar):TestDuckDBJDBCpasses excepttest_table_function_multiple_threads, which requires all 96 processors to take part in a 33-chunk scan and fails the same way on the unchanged driver on this loaded machine.TestArrow35/35 with FFM.Performance, same JDK 25, FFM vs JNI (seconds, lower is better, loaded machine): 10M ints 0.16 vs 0.20, 2M strings 0.19 vs 0.20, 50k tiny prepared queries 3.11 vs 3.65, 5k prepares 1.10 vs 1.18, decimals/dates/timestamps equal, chunk appender 0.85 vs 0.80 (noise).
Caveats:
--enable-native-access=ALL-UNNAMEDis needed to avoid the JDK warning (a future JDK will make it an error).Linker.Option.criticalis not used yet. The release jars are built in the manylinux docker images, which would need a JDK 22+ (JAVA22_HOME) to include the FFM classes.