Skip to content
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

[#2436] Unsafe*ByteBuf implementation should only invert bytes if ByteOr... #2531

Closed
wants to merge 6 commits into from

Conversation

normanmaurer
Copy link
Member

...der differ from native ByteOrder

Motivation:
Our Unsafe*ByteBuf implementation always invert bytes when the native ByteOrder is LITTLE_ENDIAN (this is true on intel), even when the user calls order(ByteOrder.LITTLE_ENDIAN). This is not optimal for performance reasons as the user should be able to set the ByteOrder to LITTLE_ENDIAN and so write bytes without the extra inverting.

Modification:
Introduce a new special SwappedByteBuf (called UnsafeDirectSwappedByteBuf) that is used by all the Unsafe*ByteBuf implementation and allows to write without inverting the bytes.

Result:
The user is be able to get the max performance even on servers that have ByteOrder.LITTLE_ENDIAN as their native ByteOrder.

…eOrder differ from native ByteOrder

Motivation:
Our Unsafe*ByteBuf implementation always invert bytes when the native ByteOrder is LITTLE_ENDIAN (this is true on intel), even when the user calls order(ByteOrder.LITTLE_ENDIAN). This is not optimal for performance reasons as the user should be able to set the ByteOrder to LITTLE_ENDIAN and so write bytes without the extra inverting.

Modification:
Introduce a new special SwappedByteBuf (called UnsafeDirectSwappedByteBuf) that is used by all the Unsafe*ByteBuf implementation and allows to write without inverting the bytes.

Result:
The user is be able to get the max performance even on servers that have ByteOrder.LITTLE_ENDIAN as their native ByteOrder.
@normanmaurer
Copy link
Member Author

@trustin please review

@ghost
Copy link

ghost commented Jun 4, 2014

Build result for #2531 at ebc1e5e: Success

@trustin
Copy link
Member

trustin commented Jun 4, 2014

Looks good. Any numbers?

@ghost
Copy link

ghost commented Jun 4, 2014

Build result for #2531 at 22867ce: Success

@ghost
Copy link

ghost commented Jun 4, 2014

Build result for #2531 at 09eaa00: Success

@ghost
Copy link

ghost commented Jun 5, 2014

Build result for #2531 at 2c3cb68: Success

@normanmaurer
Copy link
Member Author

I added a benchmark and here is the outcome:

# Run complete. Total time: 00:08:33

Benchmark                                                      (size)   Mode   Samples        Score  Score error    Units
i.n.m.b.SwappedByteBufBenchmark.swappedByteBufSetInt            16384  thrpt        50   405887,001    15480,509   ops/ms
i.n.m.b.SwappedByteBufBenchmark.swappedByteBufSetLong           16384  thrpt        50   395321,361    16873,232   ops/ms
i.n.m.b.SwappedByteBufBenchmark.swappedByteBufSetShort          16384  thrpt        50   394809,790    16398,238   ops/ms
i.n.m.b.SwappedByteBufBenchmark.unsafeSwappedByteBufSetInt      16384  thrpt        50   433336,885     5425,122   ops/ms
i.n.m.b.SwappedByteBufBenchmark.unsafeSwappedByteBufSetLong     16384  thrpt        50   410567,013    20569,096   ops/ms
i.n.m.b.SwappedByteBufBenchmark.unsafeSwappedByteBufSetShort    16384  thrpt        50   420242,563     9492,711   ops/ms
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 514.41 sec - in io.netty.microbench.buffer.SwappedByteBufBenchmark

@ghost
Copy link

ghost commented Jun 5, 2014

Build result for #2531 at 204f022: Success

@trustin
Copy link
Member

trustin commented Jun 5, 2014

# Run complete. Total time: 00:08:30

Benchmark                                                      (size)   Mode   Samples        Score  Score error    Units
i.n.m.b.SwappedByteBufBenchmark.swappedByteBufSetInt            16384  thrpt        50   503947.893     1872.148   ops/ms
i.n.m.b.SwappedByteBufBenchmark.swappedByteBufSetLong           16384  thrpt        50   493432.696     1558.526   ops/ms
i.n.m.b.SwappedByteBufBenchmark.swappedByteBufSetShort          16384  thrpt        50   471919.077     1369.403   ops/ms
i.n.m.b.SwappedByteBufBenchmark.unsafeSwappedByteBufSetInt      16384  thrpt        50   505885.088      969.096   ops/ms
i.n.m.b.SwappedByteBufBenchmark.unsafeSwappedByteBufSetLong     16384  thrpt        50   506787.121      889.898   ops/ms
i.n.m.b.SwappedByteBufBenchmark.unsafeSwappedByteBufSetShort    16384  thrpt        50   485736.824     1707.877   ops/ms

@trustin
Copy link
Member

trustin commented Jun 5, 2014

Please merge.

@trustin
Copy link
Member

trustin commented Jun 5, 2014

Perhaps this could be merged to all 4.x branches, too.

@normanmaurer
Copy link
Member Author

@trustin Yep :) I think in 4.0, 4.1 and master ?

@normanmaurer
Copy link
Member Author

@trustin lol yeah,.. you was faster :)

@normanmaurer normanmaurer deleted the byteorder_native_fix branch June 5, 2014 09:10
@normanmaurer
Copy link
Member Author

alright... cherry-picked into 4.0, 4.1 and master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants