-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[java-generator] performance improvementes #4867
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing job @mariofusco 🎉 🚀 🚀 🚀
Thanks a ton!!!
A minor style nitpick and it's good to go.
Can you share the perf difference before/after this change?
|
||
int i = 0; | ||
for (WritableCRCompilationUnit w : wCUs) { | ||
futures[i++] = CompletableFuture.runAsync(() -> w.writeAllJavaClasses(basePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you attempted to use a different Thread Pool than the ForkJoinPool.commonPool
since it's used also by the underlying parallelStreams
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At that point the code generation performed in the parallel stream is finished and that pool should be completely available to write files. Also consider that creating a brand new thread pool could be very likely much more expansive than writing the file, that's why imo it is a better idea to reuse an already existing pool. Anyway if we had the JMH benchmark that I'm proposing in the other comment we could properly measure this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find the yaml I was using here: https://github.com/kserve/kserve/releases/download/v0.10.0/kserve.yaml
feel free to add it to the CompilationTest
along with this PR.
Feel free to add a JMH benchmark if you think that it's useful, but I'm convinced that this PR is perfectly enough for a first iteration.
In case performance issues becomes a problem we can revisit the implementation later on 👍
Thanks again!
private void writeCRCompilationUnits(File basePath, List<WritableCRCompilationUnit> wCUs) { | ||
CompletableFuture<Void>[] futures = new CompletableFuture[wCUs.size()]; | ||
|
||
int i = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] can you, please, move wCUs.size()
to a val (e.g. total
) and reuse it as a boundary in the following for
loops?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
CompletableFuture<Void>[] futures = new CompletableFuture[wCUs.size()]; | ||
|
||
int i = 0; | ||
for (WritableCRCompilationUnit w : wCUs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (WritableCRCompilationUnit w : wCUs) { | |
for (int i = 0; i < total; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
futures[i++] = CompletableFuture.runAsync(() -> w.writeAllJavaClasses(basePath)); | ||
} | ||
|
||
for (int j = 0; j < futures.length; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int j = 0; j < futures.length; j++) { | |
for (int j = 0; j < total; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
In reality I can no longer run my main because I don't have anymore the yaml that I was using to test it. Is it possible to push it on main or somewhere else? That said I'm afraid that the code generation triggered by that file doesn't last long enough to see any reliably measurable difference. Maybe we could find a bigger test case and put it in a JMH benchmark? |
I added a JMH benchmark to demonstrate the performance improvement of this PR and got the following results. Before this PR:
After
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing job @mariofusco , good to go! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx!
Awesome job 🙌
SonarCloud Quality Gate failed. |
Fix #4865
This PR:
StaticJavaParser.parseClassOrInterfaceType
with explicit javaparser AST nodes constructors