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
Java: Fast writing of vectors #4881
Comments
That is likely quicker, yes. Of course, rather than calling the above function, you can call |
I think any advantage might only be for cases where the source data is in a byte[] as I haven't found a way to transfer data from a double[] to a byte[] that doesn't involve a loop over each double at some point. |
Sure, we can generate special purpose code just for |
This issue has been automatically marked as stale because it has not had activity for 1 year. It will be automatically closed if no further activity occurs. To keep it open, simply post a new comment. Maintainers will re-open on new activity. Thank you for your contributions. |
Is there any update on this? I am dealing with These bulk operations should be fine for the most common case where the systems where the buffers are (de-) serialized share the same endianness and bit representation and above snippets could be a fall-back if, for example, the endianness does not match. |
@RalphSteinhagen not that I know.. care to make a PR? |
@aardappel basically sort-of-yes (since we have a working/tested prototype in another serializer that could be 'transplanted'), but overall depends on the time-line, support w.r.t. secondary issues/features, and whether other users would be interested in this as well. The primary proof-of-concept (ie. same from/to architecture) is simple, but there are secondary questions like API changes, design choices (e.g. using JDK's Unsafe classes or NIO only), how to track/handle mixed-architectures for sender/receiver, reference implementations for C++/Java/.. etc. that would need to be followed up as well. The individual items are rather easy but the sum ... This would be particularly important since there is already a strong/diverse user community around Flatbuffers... |
@RalphSteinhagen I thought the above would just either modify that generated loop to use |
@aardappel well, unfortunately, it doesn't seem to be that simple (N.B. I dived a bit into the underlying source code): A lot of interfaces, wrappers etc. would need to be bypassed to do this efficiently.... Among other things, In some other serializer implementations, the array is taken from user-space, appended behind a small header that describes the array/primitive data format and then directly (low-level array) copied to the resulting byte-buffer... not impossible but a couple of days work and many API changes that would be only warranted if there is also a strong use-case by other users... |
@RalphSteinhagen not that I see..
You appear to be reading the code for FlexBuffers. Check FlatBufferBuilder.java @paulovap may have an opinion. |
For FlatBuffers the builder is backed by an NIO's Looping over a naked array might be helped by range check elimination done by some VMs and AFAIK you cannot get it from accessing bytes or doubles on As @aardappel suggested |
@aardappel yes, was looking into the FlexBuffers builder. The FlatBufferBuilder as a sort of wrapper around the NIO ByteBuffer could indeed be more easily adapted to just support doubles but does not seem to allow insertions/additions without breaking the overall wire data format structure. As a premise, I was looking into loosely coupled protocols where the server- (sending) side can evolve with time and the client (since there are many diverse ones) do not necessarily have to adapt the scheme for each micro-changes (ie. usually additional fields). Maybe a different use-case than FlatBuffers is designed for. In comparison with other protocols, I found that the vector routines are rather slowish and I thought I'd make a mistake w.r.t. the usage of FlatBuffers (/FlexBuffers), thus my initial question. |
@RalphSteinhagen FlexBuffers is its own format that's different from FlatBuffers in many ways. They can be used together but are not interchangeable. And FlatBuffers was totally designed for adding and removing fields. |
Just found this via Google search. @aardappel are you still open to accepting the change proposed, ie. |
@evanf-humane yes that would be very welcome I am sure. Please check the above discussion w.r.t. endianess and other issues. |
What is the fastest way to write a large vector in Java? The generated code does a loop over every element in an array.
For example in my flatbuffers generated code:
Is there any way to use a System.arraycopy somehow which may be quicker?
The text was updated successfully, but these errors were encountered: