Skip to content

Avoid unnecessary ByteString concat for strict HTTP/2 entities#1021

Closed
He-Pin wants to merge 1 commit into
mainfrom
optimize-http2-strict-data-collection
Closed

Avoid unnecessary ByteString concat for strict HTTP/2 entities#1021
He-Pin wants to merge 1 commit into
mainfrom
optimize-http2-strict-data-collection

Conversation

@He-Pin
Copy link
Copy Markdown
Member

@He-Pin He-Pin commented Apr 27, 2026

Motivation:
HTTP/2 DATA aggregation for small strict request entities may concatenate an empty ByteString with the incoming payload. That adds unnecessary work and allocation on unary/small-request gRPC-like paths without changing stream semantics.

Modification:

  • keep the existing collecting state machine
  • avoid collectedData ++ payload when either side is empty

Result:
The first DATA frame on the strict collection path now reuses the existing payload reference instead of allocating a concatenated ByteString. Non-empty aggregation behavior is unchanged.

Verification:

  • sbt "http-core / scalafmtCheck" "http2-tests / Test / testOnly org.apache.pekko.http.impl.engine.http2.Http2ServerSpec -- -z collect"

Risk / Boundary:

  • HTTP/2 stream state transitions are unchanged
  • the change is limited to the empty/non-empty ByteString boundary
  • existing HTTP/2 collection tests pass

@He-Pin He-Pin added this to the 2.0.0-M2 milestone Apr 27, 2026
@He-Pin He-Pin requested a review from pjfanning April 27, 2026 06:21
@pjfanning
Copy link
Copy Markdown
Member

ByteString ++ already checks if either the left or right bytestring is empty and then does not return a new ByteStrings instance.

@He-Pin He-Pin removed this from the 2.0.0-M2 milestone Apr 27, 2026
@He-Pin He-Pin closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants