ubjson / universal-binary-json-java

Universal Binary JSON Java Library
http://ubjson.org
Apache License 2.0
33 stars 4 forks source link

Universal Binary JSON Java Library http://ubjson.org

About this project...

This code base is actively under development and implements the latest specification of Universal Binary JSON (Draft 8).

I/O is handled through the following core classes:

* UBJOutputStream
* UBJInputStream
* UBJInputStreamParser

Additionally, if you are working with Java's NIO and need byte[]-based results, you can wrap any of the above I/O classes around one of the highly optimized custom byte[]-stream impls:

* ByteArrayInputStream  (optimized for reuse, not from JDK)
* ByteArrayOutputStream (optimized for reuse, not from JDK)

If you are working with NIO and want maximum performance by using (and reusing) direct ByteBuffers along with the UBJSON stream impls, take a look at the:

* ByteBufferInputStream
* ByteBufferOutputStream

classes. You can wrap any ByteBuffer source or destination with this stream type, then wrap that stream type with a UBJSON stream impl and utilize the full potential of Java's NIO with Universal Binary JSON without giving yourself an ulcer.

This allows you to re-use the streams over and over again in a pool of reusable streams for high-performance I/O with no object creation and garbage collection overhead; a perfect match for high frequency NIO-based communication.

All of the core I/O classes have been stable for a while, with tweaks to make the performance tighter and the error messages more informative over the last few months.

More Java-convenient reflection-based I/O classes are available in the org.ubjson.io.reflect package, but they are under active development.

There are other efforts (like utilities) in other sub portions of the source tree. This project intends to eventually contain a multitude of UBJSON abstraction layers, I/O methods and utilities.

Changelog

02-10-12

02-09-12

02-07-12 More Memory and CPU optimizations across all the I/O impls.

* StreamDecoder was rewritten to no longer create a ByteBuffer on every
invocation and instead re-use the same one to decode from on every single call.

* StreamDecoder now requires the call to pass in a CharBuffer instance to hold
the result of the decode operation. This avoids the creation of a CharBuffer
and allows for large-scale optimization by re-using existing buffers between
calls.

* StreamEncoder was rewritten to no longer create a ByteBuffer on every
invocation either and now re-uses the same single instance over and over
again.

* UBJOutputStream writeHuge and writeString series of methods were all
rewritten to accept a CharBuffer in the rawest form (no longer char[]) to stop
hiding the fact that the underlying encode operation required one.

This gives the caller an opportunity to cache and re-use CharBuffers over 
and over again if they can; otherwise this just pushes the CharBuffer.wrap() 
call up to the caller instead of hiding it secretly in the method impl under 
the guise of accepting a raw char[] (that it couldn't use directly).

For callers that can re-use buffers, this will lead to big performance gains
now that were previously impossible.

* UBJInputStream added readHuge and readString methods that accept an existing
CharBuffer argument to make use of the optimizations made in the Stream encoder
and decoder impls.

01-15-12 Huge performance boost for deserialization!

StreamDecoder previously used separate read and write buffers for decoding 
bytes to chars including the resulting char[] that was returned to the caller. 
This design required at least 1 full array copy before returning a result in 
the best case and 2x full array copies before returning the result in the 
worst case.

The rewrite removed the need for a write buffer entire as well as ALL array
copies; in the best OR worse case they never occur anymore.

Raw performance boost of roughly 25% in all UBJ I/O classes as a result. 

12-01-11 through 01-24-12 A large amount of work has continued on the core I/O classes (stream impls) to help make them not only faster and more robust, but also more helpful. When errors are encountered in the streams, they are reported along with the stream positions. This is critical for debugging problems with corrupt formats.

Also provided ByteArray I/O stream classes that have the potential to provide
HUGE performance boosts for high frequency systems.

Both these classes (ByteArrayInputStream and ByteArrayOutputStream) are
reusable and when wrapped by a UBJInputStream or UBJOutputStream, the top
level UBJ streams implicitly become reusable as well.

Reusing the streams not only saves on object creation/GC cleanup but also
allows the caller to re-use the temporary byte[] used to translate to and
from the UBJ format, avoiding object churn entirely!

This optimized design was chosen to be intentionally performant when combined
with NIO implementations as the ByteBuffer's can be used to wrap() existing
outbound buffers (avoiding the most expensive part of a buffer) or use
array() to get access to the underlying buffer that needs to be written to
the stream.

In the case of direct ByteBuffers, there is no additional overhead added
because the calls to get or put are required anyway to pull or push the 
values from the native memory location.

This approach allows the fastest implementation of Universal Binary JSON
I/O possible in the JVM whether you are using the standard IO (stream) 
classes or the NIO (ByteBuffer) classes in the JDK.

Some ancillary work on UBJ-based command line utilities (viewers, converters,
etc.) has begun as well.

11-28-11

11-27-11

11-26-11

11-10-11

10-14-11

10-10-11

09-27-11

Status

Using the standard UBJInputStream, UBJInputStreamParser and UBJOutputStream implementations to manually read/write UBJ objects is stable and tuned for optimal performance.

Automatic mapping of objects to/from UBJ format via the reflection-based implementation is not tuned yet. Writing is implemented, but not tuned for optimal performance and reading still has to be written.

* org.ubjson.io - STABLE
* org.ubjson.io.parser - STABLE
* org.ubjson.io.reflect - ALPHA
* org.ubjson.model - BETA

License

This library is released under the Apache 2 License. See LICENSE.

Description

This project represents (the official?) Java implementations of the Universal Binary JSON specification: http://ubjson.org

Example

Comming soon...

Performance

Comming soon...

Reference

Universal Binary JSON Specification - http://ubjson.org JSON Specification - http://json.org