Repository navigation
Conversation
Motivation: ReferenceCountedOpenSslEngine.unwrap(...) calls SSL.sslPending(...) through JNI at the start of every call once the handshake is finished. The value is only read when there is nothing to feed into the BIO (the sources are empty) or after a destination buffer was filled, so for the common case of one non-empty source it is never used. On a server handling many small TLS records the call shows up as ~1.7% of CPU samples in a production profile. Modification: - Do not query SSL_pending up front. Fetch it where it is read: when the sources are empty, and when an empty source buffer is met in the loop. - Add a test that unwraps one record into a too small destination and then drains the plaintext left inside the engine through an empty source and through an empty source that is one of multiple sources. Result: One JNI call less per unwrap in the common case. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeEBW1t95tykU91d9HehxQ
wrapFullRecord(...) only accepts MAX_PLAINTEXT_LENGTH bytes, so the test now wraps a full record and drains it in three parts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeEBW1t95tykU91d9HehxQ
✅ All tests passed ✅🏷️ Commit: e12141f Learn more about TestLens at testlens.app/docs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
ReferenceCountedOpenSslEngine.unwrap(...)callsSSL.sslPending(...)through JNI at the start of every call once the handshake is finished. The value is only read in two places:len == 0), to decide betweenBUFFER_UNDERFLOWand draining plaintext that is still inside the engine;For the common case of one non-empty source the value is never used. In a 300 s production CPU profile of a server handling many small TLS records (Netty 4.2.20, netty-tcnative-boringssl-static 2.0.85)
SSL.sslPendingaccounts for about 1.7% of all samples.Modification:
SSL_pendingup front. Fetch it where it is read: in thelen == 0check, and on the first empty source buffer met in the loop. ASSL_PENDING_UNKNOWNsentinel marks "not queried yet";SSL_pendingnever returns a negative value. The refresh after a destination buffer is filled is unchanged.OpenSslEngineTest.testUnwrapEmptySourceDrainsPendingPlaintext: it unwraps one full record into a too small destination, then drains the plaintext left inside the engine through an empty source and through an empty source that is one of multiple sources, and checksBUFFER_UNDERFLOWonce nothing is left. Neither path had a dedicated test.Result:
One JNI call less per unwrap in the common case, with the same results.
The value used for an empty source buffer in the loop can now be newer than the one taken at the start of the call. That does not change the outcome: a newer zero skips the buffer directly, where the older non-zero value would have led to a read that returns nothing and then skipped it.