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

Defer Scannable#name() fallback logic #3900

Conversation

Stephan202
Copy link
Contributor

Depending on the implementation, Scannable#stepName() may be expensive
to invoke. As such this should only happen when necessary.

@Stephan202 Stephan202 requested a review from a team as a code owner October 3, 2024 06:59
Copy link
Contributor Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Hat tip to @werli for spotting this issue!

@@ -449,7 +449,7 @@ default String name() {
.map(s -> s.scan(Attr.NAME))
.filter(Objects::nonNull)
.findFirst()
.orElse(stepName());
.orElseGet(this::stepName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two things:

  1. In some cases #stepName is very expensive. I'll file a separate PR with benchmark for that, and link it here afterwards.
  2. I checked other Optional#orElse calls in reactor-core; the remainder accept a constant, which is fine. That said, if Reactor would like to automatically catch cases such as this one, @rickie or myself would be happy to contribute a (limited, if desired) integration with Error Prone Support, enabling checks such as this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll file a separate PR with benchmark for that, and link it here afterwards.

Done: #3901.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds reasonable to move the changes from this PR to #3901 as they are related and the whole context is there.

@Stephan202 Stephan202 force-pushed the sschroevers/defer-step-name-construction branch from e64527a to 009ec89 Compare October 3, 2024 07:07
Copy link

@werli werli left a comment

Choose a reason for hiding this comment

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

Assuming Scannable#stepName does not create important side effects, this should be a net-positive. 💪

Thanks for filing the PR @Stephan202!

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

@Stephan202 thanks for the PR. It looks promising. As suggested in the comment, can you please merge this work with the other PR? Thanks.

@@ -449,7 +449,7 @@ default String name() {
.map(s -> s.scan(Attr.NAME))
.filter(Objects::nonNull)
.findFirst()
.orElse(stepName());
.orElseGet(this::stepName);
Copy link
Member

Choose a reason for hiding this comment

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

Sounds reasonable to move the changes from this PR to #3901 as they are related and the whole context is there.

@chemicL chemicL added the status/need-user-input This needs user input to proceed label Oct 4, 2024
@Stephan202
Copy link
Contributor Author

@chemicL done: #3901 has been updated. I'll close this PR.

@Stephan202 Stephan202 closed this Oct 4, 2024
@Stephan202 Stephan202 deleted the sschroevers/defer-step-name-construction branch October 4, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-user-input This needs user input to proceed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants