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

Fix performance regression in AssertJ recipes #505

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

philippe-granet
Copy link
Contributor

@philippe-granet philippe-granet commented Apr 14, 2024

What's changed?

Since commit 368384a , AssertJ recipes are really slower since calling contextSensitive() method disable a cache on JavaTemplate.

Fixes:

@philippe-granet philippe-granet marked this pull request as ready for review April 14, 2024 15:49
Since commit openrewrite@368384a , AssertJ recipes are really slower since calling contextSensitive() method  disable a cache on JavaTemplate.

Fixes:
- Make sure there is a static import org.assertj.core.api.Assertions.* , even if not referenced (see openrewrite#491 and openrewrite#479)
- reintroduced assertionsParser cache in JUnitAssertEqualsToAssertThat
Since commit openrewrite@368384a , AssertJ recipes are really slower since calling contextSensitive() method  disable a cache on JavaTemplate.

Fixes:
- Make sure there is a static import org.assertj.core.api.Assertions.* , even if not referenced (see openrewrite#491 and openrewrite#479)
- reintroduced assertionsParser cache in JUnitAssertEqualsToAssertThat
@philippe-granet philippe-granet marked this pull request as draft April 14, 2024 16:34
Since commit openrewrite@368384a , AssertJ recipes are really slower since calling contextSensitive() method  disable a cache on JavaTemplate.

Fixes:
- Make sure there is a static import org.assertj.core.api.Assertions.* , even if not referenced (see openrewrite#491 and openrewrite#479)
- reintroduced assertionsParser cache in JUnitAssertEqualsToAssertThat
Copy link
Contributor

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

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

I think we can indeed make most of these templates context-free, as they only depend on the template parameters.

rewriteRun(
//language=java
spec -> spec.typeValidationOptions(TypeValidation.none()),
Copy link
Contributor

Choose a reason for hiding this comment

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

As it seems like this test passed the type validation before, I wonder why it doesn't anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

That test links to this issue, which was the reason to add contextSensitive as a quick solution at the time, with unfortunate runtime performance impact.

Those custom classes are not available when we drop .contextSensitive(), and the missing types would then break chained recipe runs to for instance adopt more optimal assertion patterns with AssertJ, as part of the migration.

Not quite sure where that leaves this effort. For a one time migration I'd lean towards taking the performance penalty for a more complete / idiomatic migration, but I don't know what prompted the need to fix the performance issue here. Any context there @philippe-granet ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. The template parameter's type is defined on the source path. That is a rather special case of course. So the test would also fail for a context-sensitive recipe, if the A class were defined in another source file.

I am not sure, but I would probably merge the PR and live with this limitation for now.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok; I'll trust your judgement on that then and get this merged as is. Thanks a lot both!

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks a lot for noticing, diagnosing and fixing the performance issue with these AssertJ recipes @philippe-granet !

@timtebeek timtebeek merged commit fafcb85 into openrewrite:main Apr 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants