-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch data to reduce JNI calls. #517
Comments
I need to convert |
This feature has been implemented for PackedByteArray. The main issue lies with the very first step I mentioned earlier: I don't have any way to know evaluate the required size before checking every single value stored in those containers. It would require an additional call JNI to C++ that would iterate over the containers, retrieve all the Variant in it, and compute how many buffer exchanges it would require as well as the exact content of each. It's cumbersome to implement and slow as well (even if not as slow as the current solution). I can still implement it for typed VariantArray (and soon typed Dictionaries), because the data type will be homogenous, so I just need the space taken by that type in the buffer, it would not be as optimized as the PackedArray conversions, but should be simple enough and a decent performance boost. But I don't think an optimized conversion for VariantArray or Dictionary<Any, Any> is coming anymore. |
@CedNaru I think the conversion from Kotlin's |
That one is already implemented and merged into master. We also use that conversion (well the int64 version of it) to exchange pointers quickly between Godot and the JVM now when managing memory, it works like a charm. |
There are a few places in the code where I think we can get extra performances by batching data when we know the same JNI call would need to be called several times otherwise. Such cases are:
The way to implement that would be to add new "batch" methods to TransferContext (both in C++ and Kotlin) to write and read stuff to the buffer. The buffer got quite a lot of extra space with its 8 kB after the increase to 16 parameters.
The steps of a batch call would be the following:
-Provide the batch write function with an array containing all the data.
How the VariantArray conversion to a List would be done:
TransfertContext::batch_write
with the Variant Array as a parameter.batch_write
will make as many JNI calls to the JVM as necessary to transfer all the data.The minimum cost of batching is then 2 JNI calls + an additional level of data indirection/copy (C++ Array => SharedBuffer => Kotlin Batch Container => List).
That extra work will probably be reimbursed with VariantArrays of more than 5 elements, but it's something that would need to be benchmarked.
The text was updated successfully, but these errors were encountered: