Optimize log2 in PoolThreadCache
See original GitHub issueOptimize log2 in PoolThreadCache
Currently io.netty.buffer.PoolThreadCache uses log2 implementation based on a shift loop. It is not a most efficient way: https://gist.github.com/netudima/e1e8206bf58ff0ab6e2d637a4362bfc2
NettyLog2Benchmark.bits avgt 25 2.612 ± 0.009 ns/op
NettyLog2Benchmark.cycle avgt 25 10.909 ± 0.157 ns/op
NettyLog2Benchmark.leadingZeroes avgt 25 1.921 ± 0.006 ns/op
# JMH version: 1.21
# VM version: JDK 11.0.5, OpenJDK 64-Bit Server VM, 11.0.5+10-b520.38
# CPU: 2,6 GHz 6-Core Intel Core i7
It looks like for the current versions of JDK using Integer.numberOfLeadingZeros (intrinsic) is an optimal approach.
Note: PoolChunk also has log2 but it is already implemented based on Integer.numberOfLeadingZeros.
Netty version
4.1.48, 4.0.56
JVM version (e.g. java -version
)
JDK 11.0.5, OpenJDK 64-Bit Server VM, 11.0.5+10-b520.38
OS version (e.g. uname -a
)
Darwin MBP 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Francesco Nigro on Twitter: "#java #perftip: as @nitsanw has ...
Optimize log2 in PoolThreadCache Currently io.netty.buffer.PoolThreadCache uses log2 implementation based on a shift loop. It is not a most efficient way: ...
Read more >4.1.49.Final Milestone - GitHub
Propagate ref to pool thread cache down in the allocation stack to av… #10166 by netudima was merged on ... Optimize log2 in...
Read more >Fast computing of log2 for 64-bit integers - Stack Overflow
Intrinsic functions are really fast, but still are insufficient for a truly cross-platform, compiler-independent implementation of log2.
Read more >PoolThreadCache xref - Netty
37 */ 38 final class PoolThreadCache { 39 40 private static final InternalLogger logger ... Small); 78 79 numShiftsNormalDirect = log2(directArena.
Read more >Base-2 logarithm of symbolic input - MATLAB log2 - MathWorks
This MATLAB function returns the logarithm to the base 2 of X such that 2Y = X.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for the feedback and the tip. The results of the bench: https://gist.github.com/netudima/787176639eac62ae8e4ab8430f95e883
Loop:
LeadingZeroes:
I will send a PR soon.
Anyway, feel free to send the PR “regardless” the result of the bench (hopefully positive): it’s something that makes sense to change 👍