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

Do not concatenate Publisher.empty() message body #1497

Merged
merged 1 commit into from
Apr 15, 2021

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

For HeaderUtils#setContentLength(...), when the messageBody is exactly
Publisher.empty() there are no operators applied for the messageBody.
In this case we do not need concatenation.

Modifications:

  • Skip concatenation when messageBody == empty();
  • Add tests when payloadBody is not set at all;

Result:

Less operators applied during request/response processing when not
necessary.

Motivation:

For `HeaderUtils#setContentLength(...)`, when the `messageBody` is exactly
`Publisher.empty()` there are no operators applied for the `messageBody`.
In this case we do not need concatenation.

Modifications:

- Skip concatenation when `messageBody == empty()`;
- Add tests when payloadBody is not set at all;

Result:

Less operators applied during request/response processing when not
necessary.
@idelpivnitskiy idelpivnitskiy requested a review from tkountis April 15, 2021 22:06
@idelpivnitskiy
Copy link
Member Author

@tkountis minor improvement, didn't think about it during review

@@ -177,7 +177,11 @@ public boolean mapTerminal() {
final BiIntConsumer<HttpHeaders> contentLengthUpdater) {
if (messageBody == empty() || (isPayloadEmpty(metadata) && !mayHaveTrailers(metadata))) {
contentLengthUpdater.apply(0, metadata.headers());
return from(metadata, EmptyHttpHeaders.INSTANCE).concat(messageBody.ignoreElements());
return messageBody == empty() ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does it make sense to cache this?

final boolean messageBodyEmpty = messageBody == empty();
if (messageBodyEmpty || ..) {
  return messageBodyEmpty ? ...;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's a comparison of a reference address, not sure cache will be helpful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also hope that compiler is smart enough :)

@idelpivnitskiy idelpivnitskiy merged commit 82f2dd3 into apple:main Apr 15, 2021
@idelpivnitskiy idelpivnitskiy deleted the ignore-empty branch April 15, 2021 22:52
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