-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Avoid using JVM HashCode on Http 2 DefaultStream #13760
Conversation
This has been detected on the http 2 hello world-like benchmarking, see (in violet) In case the stream's id is not good enough, given that |
The stream id is a peer controlled value we read off the network. I'm hesitant to use it here, in case it opens us op to session hijacking vulnerabilities. I'd rather we pulled a hashcode off an atomic counter, and retained object identity for equality. |
@chrisvest looking at the code paths where it is used, it shouldn't happen (because we check upfront the expected next id to create, and removal happen from within the stream itself - which means that the creation id check had worked out), said that, better be safe then sorry, and we can skip using an atomic counter here, given that the default stream code path is single threaded (you can verify it by checking the stream id check before, which uses thread unsafe fields) |
Just fyi, @chrisvest I'm recently receiving hints from users which wrongly compare http 1.1 Vs 2 (very wrongly, cause the power of http 2 is beyond hello world use cases), but effectively there are few low hanging fruits (and some not so low) which could reduce a lot the stream management cost (creation and notification), plus other improvements related known header name lookups (addresses elsewhere, in another pr), and I am trusty, we can get very similar performance by fixing everything, assuming code won't suffer too much from this effort. |
edd4161
to
a37a1f2
Compare
@chrisvest I've added a commit which is leaving equals as it is and allowing |
Motivation: relying on DefaultStream's hashCode forces calling into JVM's strategy for identity hash code Modifications: Use the stream's id to identify DefaultStream Result: Faster active stream insertion, saving producing JVM's hashcode
a37a1f2
to
d86dcec
Compare
codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java
Show resolved
Hide resolved
codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java
Show resolved
Hide resolved
codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java
Show resolved
Hide resolved
@franz1981 thanks a lot! |
Motivation: relying on DefaultStream's hashCode forces calling into JVM's strategy for identity hash code Modifications: Use the stream's id to identify DefaultStream Result: Faster active stream insertion, saving producing JVM's hashcode
Motivation: relying on DefaultStream's hashCode forces calling into JVM's strategy for identity hash code Modifications: Use the stream's id to identify DefaultStream Result: Faster active stream insertion, saving producing JVM's hashcode
Motivation:
relying on DefaultStream's hashCode forces calling into JVM's strategy for identity hash code
Modifications:
Use the stream's id to identify DefaultStream
Result:
Faster active stream insertion, saving producing JVM's hashcode