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

Improve performance of Java package parser by making it a Bazel worker #3686

Merged
merged 2 commits into from May 10, 2023

Conversation

keithl-stripe
Copy link
Contributor

@keithl-stripe keithl-stripe commented Jun 14, 2022

Checklist

  • I have filed an issue about this change
  • and discussed potential changes with the maintainers.
  • I have received the approval from the maintainers to make this change.
  • This is not a stylistic, refactoring, or cleanup change.

Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.

Discussion thread for this change

Issue number: #3685

Description of this change

Makes the package parser tool (a Java CLI application) able to be run as a Bazel worker. Also modify the Starlark to enable worker mode.

@@ -704,6 +712,10 @@ def build_java_package_manifest(ctx, target, source_files, suffix):
arguments = [args],
mnemonic = "JavaPackageManifest",
progress_message = "Parsing java package strings for " + str(target.label),
execution_requirements = {

Choose a reason for hiding this comment

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

I think it would be great to also support multiplexed workers here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@keithl-stripe is this something that makes sense from your perspective?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but for now that's a "nice to have" - I believe it would simply improve overall performance, but should not be a blocker for this PR.

@Bencodes
Copy link

Bencodes commented Jul 6, 2022

@mai93 can you take a look at this?

@mai93 mai93 requested a review from jastice July 7, 2022 17:46
@jastice jastice requested review from mai93 and tpasternak and removed request for vsiva and alice-ks July 21, 2022 15:28
Copy link
Collaborator

@jastice jastice left a comment

Choose a reason for hiding this comment

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

LGTM. Any problems you see @mai93 ?

Comments from @keithl-stripe in chat:

AFAIK generally workers have some risks:

  1. could add to memory footprint of a build, e.g accidental state or uncollected garbage, or simply the fact that bazel keeps workers running between builds
  2. bugs could be hard to track down when they are the result of built up state

1️⃣ doesn’t seem likely, as this worker doesn't do much, but it might be worth experimenting with Xmx values

2️⃣ this worker doesn't carry any meaningful state beyond just the JVM’s own state

@@ -704,6 +712,10 @@ def build_java_package_manifest(ctx, target, source_files, suffix):
arguments = [args],
mnemonic = "JavaPackageManifest",
progress_message = "Parsing java package strings for " + str(target.label),
execution_requirements = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@keithl-stripe is this something that makes sense from your perspective?

parsePackagesAndWriteManifest(parser, workRequestOptions);

builder.build().writeDelimitedTo(System.out);
} catch (Exception e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering whether we should catch all exceptions this way here. In case an exception is thrown, the loop will still run. Maybe we should allow continuation of the loop only when "parsePackagesAndWriteManifest" throws a parsing-specific exception, and for other errors break the loop. The BazelJavaBuilder is doing so

https://github.com/bazelbuild/bazel/blob/a4251eab6988d6cf4f5e35681fbe2c1b0abe48ef/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java#L45-L55

But I'm not sure, otherwise LGTM 👍

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 wanted to reduce the risk that we crash hard for an issue that only affects the current action. I honestly don't know what is best here. If you'd like me to be more conservative that's fine - will update the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally I would prefer to follow the same way as BazelJavaBuilder. For recoverable exceptions we can continue, but for unexpected ones System.exit would be more transparent. We could also print a message telling the user it is possible to run it without persistent workers.

@Bencodes
Copy link

@keithl-stripe There are a few other actions in this repo like CreateAar and JarFilter that would benefit greatly from having worker support. Can this worker implementation be made a bit more generic so that we can support those as well?

@mai93 mai93 requested a review from estebandlc July 29, 2022 20:26
@mai93
Copy link
Collaborator

mai93 commented Jul 29, 2022

@estebandlc I would like to get your feedback on this PR.

@sgowroji sgowroji added product: IntelliJ IntelliJ plugin topic: sync Issues related to the sync operation awaiting-review Awaiting review from Bazel team on PRs labels Sep 2, 2022
@sgowroji sgowroji added awaiting-user-response Awaiting response from author on PRs and removed awaiting-review Awaiting review from Bazel team on PRs labels Oct 6, 2022
@sgowroji
Copy link
Member

sgowroji commented Oct 6, 2022

Hello @keithl-stripe, Could you please resolve the above code conflicts and help us in submitting it. Thanks!

@mai93 mai93 self-assigned this Oct 6, 2022
@keithl-stripe
Copy link
Contributor Author

Sorry, we are moving away from using this plugin here at Stripe, so we are investing our effort in our homegrown IntelliJ plugin. Someone else will have to pick up this PR and get it landed if people think it would be useful. (It sped up our sync builds substantially!)

@jastice
Copy link
Collaborator

jastice commented Oct 13, 2022

Okay, then let's keep this open as a work item for maintainers or other contributors. Thank you for the effort so far!

@jastice jastice removed the awaiting-user-response Awaiting response from author on PRs label Oct 13, 2022
@mai93 mai93 removed their assignment Oct 18, 2022
@mai93 mai93 added the awaiting-review Awaiting review from Bazel team on PRs label Dec 5, 2022
@mai93 mai93 self-assigned this May 4, 2023
@mai93 mai93 removed their assignment May 9, 2023
@tpasternak
Copy link
Collaborator

tpasternak commented May 10, 2023

If there are no other objections let's merge it now
cc @mai93

@mai93
Copy link
Collaborator

mai93 commented May 10, 2023

I'm ok with that, can you fix the conflict then merge it? It is already approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Awaiting review from Bazel team on PRs product: IntelliJ IntelliJ plugin topic: sync Issues related to the sync operation
Projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants