Skip to content
Commit 162f86dd authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

More efficient alternatives to ByteBuffer.

Some upcoming binary XML work needs to efficiently read and write
raw bytes, and we initially started using ByteBuffer.  However, that
design had additional overhead since we were performing bounds checks
twice (once to fill/drain buffers, then again to parse data).  In
addition, the upstream ByteBuffer makes per-byte method invocations
internally, instead of going directly the the buffer.

This change introduces FastDataInput/Output as local implementations
of DataInput/Output which are focused on performance.  They also
handle fill/drain from an underlying Input/OutputStream, and the
included benchmarks show reading 3x faster and writing 2x faster:

    timeRead_Upstream_mean: 5543730
    timeRead_Local_mean: 1698602

    timeWrite_Upstream_mean: 3731119
    timeWrite_Local_mean: 1885983

We also use the new CharsetUtils methods to write UTF-8 values
directly without additional allocations whenever possible.  This
requires using a non-movable buffer to avoid JNI overhead to gain
the 30% benchmarked performance wins.

Bug: 171832118
Test: atest CorePerfTests:com.android.internal.util.FastDataPerfTest
Test: atest FrameworksCoreTests:com.android.internal.util.FastDataTest
Change-Id: If28ee381adb528d03cc9851d78236d985b6ede16
parent 7a38dcc9
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment