Repository navigation
Description
A query vector passed from Python as a list, or as a float64 numpy array in a named parameter on the JVM build, spends 0.5 to 0.6 ms converting before the engine starts. A 1536-d vectorNeighbors query itself takes about 0.3 to 0.75 ms, so list input can roughly double the time per query. A float32 array does not have the cost.
The cost is in the conversion the bindings do, measured on the wheels of main e60a748 (one 1536-d vector; encode time is information, not a timing claim):
| wheel | form | path | bytes | boxed objects | encode us |
|---|---|---|---|---|---|
| native | f32 | json stub + float32 side buffer | 6181 | 0 | 4.55 |
| native | f64 | json stub + float32 side buffer | 6181 | 0 | 5.75 |
| native | list | JSON number text | 34199 | 0 | 586.56 |
| jvm | f32 | java float[] (one buffer copy) | 6144 | 0 | 7.47 |
| jvm | f64 | java.util.ArrayList of boxed numbers (1536 objects) | 12288 | 1536 | 548.0 |
| jvm | list | java.util.ArrayList of boxed numbers (1536 objects) | 12288 | 1536 | 527.54 |
The table comes from a harness that times convert_python_to_java (JVM wheel) and encode_params (native wheel) directly on one 1536-d vector for each input form (float32 array, float64 array, Python list), and counts the bytes handed over and the boxed objects. Encode time is information, not a timing claim. Because it calls those two functions directly, a re-check on current main (40ce107) reads the real entry points, Database._java_parameters and encode_params:
| wheel | form | positional | named |
|---|---|---|---|
| jvm | f32 array | Object[] holding a float[] |
HashMap holding a float[] |
| jvm | f64 array | Object[] holding a float[] (already one buffer, rounded to float32) |
HashMap holding an ArrayList of 1536 Double (the slow case) |
| jvm | list | Object[] holding an ArrayList of 1536 Double |
same inside the HashMap |
| native | any float array | float32 side buffer | float32 side buffer |
| native | list | JSON number text | JSON number text |
So the cost is still there on current main in three places: a list on either build, and a float64 array in a named parameter on the JVM build (convert_python_to_java turns it into value.tolist() and boxes each number, src/arcadedb/type_conversion.py). A positional float64 array on the JVM build was already one float[] through to_java_float_array, so the "f64" row above applies to the named form only.
The conversion points:
- JVM, list and nested values:
convert_python_to_java, theisinstance(value, (list, tuple))branch insrc/arcadedb/type_conversion.py. JPype boxes each Python float with one call into the JVM. - JVM, float64 array: the
numpy.ndarraybranch of the same function (value.tolist()then the list branch). - Native, list:
_prepandencode_paramsinsrc/arcadedb/_native/codec.py; the list is written as JSON text byjson.dumps, which formats every number as text.
A list parameter is not always a vector, so the fix must not turn every numeric list into float32. WHERE x IN :ids, list properties, equality, CONTAINS, ints that must stay ints, None, strings and nested lists all have to read exactly what they read today. The plan: send a list that holds only Python floats (long ones) as one double[] that Java boxes into the same ArrayList<Double> on the JVM build, send a float64 array the same way, and on the native build send such a list in the existing float32 side buffer only when float32 holds every number exactly (a list from a float32 model does), with a new tag that the Java side reads as a List<Double>. Everything else keeps its path, and np.asarray(v, dtype=np.float32) is documented as the fast path.
Edit: removed a reference to a private notes path.
Activity
A long float list, or a float64 array in a named parameter, crosses a…