Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@paulovap
Copy link
Contributor

@paulovap paulovap commented Aug 10, 2019

Implementation of FlexBuffers API

This is the initial attempt to implement FlexBuffer on Java.

There is some limitations as compared to the C++ implementation:
1 - No mutations implemented yet
2 - Does not parse from json

Also, this initial implementation is not focused and performance, but
get the basics write. So there is many opportunities for optimization, for instance,
remove all enums, return CharSequence instead of Strings and object pooling.

A small tool called flexb which I am using to convert json data into FlexBuffers so it can test easily while implementing the features.

I think it useful as flatc does not convert to flexbuffers.

I am submitting this PR as WIP in order to get early feedback and improve API or whatever can be found early.

@paulovap paulovap force-pushed the flexbuffers_java branch 2 times, most recently from e6fabe4 to a6a5178 Compare August 17, 2019 21:45
@paulovap paulovap changed the title WIP [FlexBuffers][Java] Initial implementation of FlexBuffers API [FlexBuffers][Java] Implementation of FlexBuffers API Aug 17, 2019
Copy link
Collaborator

@aardappel aardappel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally great! Some ideas on efficiency though..

This is the initial attemp to implement FlexBuffer on Java.

There is some limitations as compared to the C++ implementation:
  1 - No mutations implemented yet
  2 - Does not parse from json

Also, this initial implementation is not focused and performance, but
get the basics write. So there is many opportunities for optimization, for instance,
remove all enums, return CharSequence instead of Strings and object pooling.
@paulovap paulovap force-pushed the flexbuffers_java branch 2 times, most recently from f63c6b6 to 1c7e2da Compare August 24, 2019 14:23
This change removes BitWidth enum in favor of static ints. Also
make all "reads" APIs closer to C++ implementation (try to cast or convert
as much as possible, assuming user knows what he is doing). Finally,
we remove the helper classes for building vectors and maps.

There is no official benchmarks, but the unit tests are running in less
than 50% for previous runs, which mean those optimizations are worth it.
There was a incorrect assumption that strings would be null-terminated, which
could lead to truncated strings. S now it relies size instead of null-termination.

Other minor improvements
@aardappel
Copy link
Collaborator

Ok, looks like we're in a good position to merge. Anything else?

@aardappel
Copy link
Collaborator

Oh, how about some doc updates? Mention it in JavaCShaprUsage.md, FlexBuffers.md. In the latter, we can have a new section, usage in Java, and rename the existing section Usage in C++. Maybe note before that section that C++, Java are the only supported languages so far (with an external Swift port available). Don't feel the need to make the examples in Java as big as in C++, at least one small example would be good, whatever you feel works.

@paulovap
Copy link
Contributor Author

Ok, looks like we're in a good position to merge. Anything else?

I believe basic functionality is there, so I think it is good enough. I have a bunch other ideas I want to explore (specially transform json -> flexb). But it make sense to write it down somewhere and discuss with you first before jump into more coding.

Oh, how about some doc updates? Mention it in JavaCShaprUsage.md, FlexBuffers.md. In the latter, we can have a new section, usage in Java, and rename the existing section Usage in C++. Maybe note before that section that C++, Java are the only supported languages so far (with an external Swift port available). Don't feel the need to make the examples in Java as big as in C++, at least one small example would be good, whatever you feel works.

Makes sense. Would it be okay to add it in a separate PR? 1800+ lines in a single PR is already annoying me.

@aardappel
Copy link
Collaborator

Ok, that's fine. If you can make the doc updates the first PR that be great.

Thanks for the hard work! A nice feature addition :)

@aardappel aardappel merged commit 8e6cabb into google:master Aug 29, 2019
@aardappel
Copy link
Collaborator

Just pushed small fix: 9b13201

LuckyRu pushed a commit to LuckyRu/flatbuffers that referenced this pull request Oct 2, 2020
* [FlexBuffers][Java] Implementation of FlexBuffers API

This is the initial attemp to implement FlexBuffer on Java.

There is some limitations as compared to the C++ implementation:
  1 - No mutations implemented yet
  2 - Does not parse from json

Also, this initial implementation is not focused and performance, but
get the basics write. So there is many opportunities for optimization, for instance,
remove all enums, return CharSequence instead of Strings and object pooling.

* [FlexBuffers][Java] Optimizations and simplification of the Builder  API.

This change removes BitWidth enum in favor of static ints. Also
make all "reads" APIs closer to C++ implementation (try to cast or convert
as much as possible, assuming user knows what he is doing). Finally,
we remove the helper classes for building vectors and maps.

There is no official benchmarks, but the unit tests are running in less
than 50% for previous runs, which mean those optimizations are worth it.

* [FlexBuffers][Java] Fix Reference::asString behavior

There was a incorrect assumption that strings would be null-terminated, which
could lead to truncated strings. S now it relies size instead of null-termination.

Other minor improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants