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

Multi-address client: take advantage of lowercase scheme #2975

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

idelpivnitskiy
Copy link
Member

@idelpivnitskiy idelpivnitskiy commented Jun 17, 2024

Motivation:

In #2938 we made it guaranteed that HttpRequestMetaData#scheme() result is always in lowercase. We can use that to simplify scheme checks inside DefaultMultiAddressUrlHttpClientBuilder.

Modifications:

  • Replace all scheme checks from equalsIgnoreCase to equals;
  • Extract exact same instance of https string from Uri3986 to speed up equals check;

Result:

No need to worry about cases for scheme check.

Motivation:

In apple#2938 we made it guaranteed that `HttpRequestMetaData#scheme()`
result is always in lowercase. We can use that to simplify scheme checks
inside `DefaultMultiAddressUrlHttpClientBuilder`.

Modifications:
- Replace all scheme checks from `equalsIgnoreCase` to `equals`;

Result:

No need to worry about cases for scheme check.
Copy link
Contributor

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

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

I'm not strongly opinionated about the examples so feel free to change or ship as-is.

Comment on lines +103 to +104
// Use HttpRequestMetaData to access "https" constant used by Uri3986 class to optimize "equals" check to be a
// trivial reference check.
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

The selectClient was about 10% of CPU on the flame graph. There will be a few more follow-ups in this area, I'm just trying to isolate independent changes in separate PRs

@@ -44,7 +44,7 @@ interface SingleAddressInitializer<U, R> {
/**
* Configures the passed {@link SingleAddressHttpClientBuilder} for the given {@code scheme} and
* {@code address}.
* @param scheme The scheme parsed from the request URI.
* @param scheme The scheme parsed from a {@link HttpRequestMetaData#requestTarget() request URI} in lowercase.
Copy link
Member Author

Choose a reason for hiding this comment

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

What about this? Should we freeze this contract in javadoc or also leave us some flexibility?
The javadoc for HttpRequestMetaData#schem() already says it's always in lowercase.

Copy link
Member Author

Choose a reason for hiding this comment

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

Decided to keep this PR purely internal. If you feel we need to update javadoc, I will open a follow-up

@idelpivnitskiy idelpivnitskiy merged commit ff218cc into apple:main Jun 17, 2024
11 checks passed
@idelpivnitskiy idelpivnitskiy deleted the lowercaseScheme branch June 17, 2024 22:30
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