bazelbuild / vscode-bazel

Bazel support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel
Apache License 2.0
231 stars 76 forks source link

Extension defaults cause other bazel commands to hang on a significantly large repos #395

Open Aghassi opened 1 month ago

Aghassi commented 1 month ago

I beleive this Bazel extension is running a very expensive query. This is fine on a small repo, but on a large monorepo this basically prevents the user from running any other bazel commands till this is done. Specifically I found the process to be running this

bazel query kind('.* rule', ...) --output=proto --proto:output_rule_attrs='' --nopro

The ... in there will take forever on a larger repo. I believe the culprit is this line https://github.com/bazelbuild/vscode-bazel/blob/e5c95e4567a80c82ada48031c9fde5561fc7c957/src/bazel/bazel_query.ts#L64

This could be improved by adding this flag https://bazel.build/reference/command-line-reference#flag--preemptible by default.

While I do understand the default setting is ..., I'd love to understand better what the recommendation is for larger repos.

vogelsgesang commented 1 month ago

The long-term direction would be using a separate output base for the query bazel commands used in the background. The "Using a separate output base" section in the README provides some instructions in that direction. I personally don't know how well this works, though, since at my day job we are still at Bazel 6.4, and I hence didn't use this setting myself on any larger repositories, yet...

However, it is of course annoying that this extension currently blocks by default for large repositories... Even worse, there is no way for the user to easily see what's going on. I am not yet sure what a good "onboarding experience" would be here

My current idea would be: Run the bazel query in a "background task" terminal, i.e. a window where users could actually inspect the output. By default, this terminal does not have the focus. If we see that a bazel query is running for more than 5 seconds, display a notification which offers a "Show Bazel output" button that focuses the background task, such that users can see what is going on

vogelsgesang commented 1 week ago

I thought a bit more about this aspect

However, it is of course annoying that this extension currently blocks by default for large repositories... Even worse, there is no way for the user to easily see what's going on. I am not yet sure what a good "onboarding experience" would be here

Instead of eagerly loading the tree of Bazel targets, we should probably only run the bazel query after some initial user interaction, e.g., if the user pressed a "Refresh Bazel Targets" button

mnoah1 commented 1 week ago

(Adding this here as I believe this issue relates to our slack discussion @vogelsgesang). The targets tree/querying portion is another potential candidate for an enable/disable setting. In our case we have a larger monorepo and users would need to know to adjust this scope to match their projects, or they'll get a very large query (in our case we just added a placeholder pattern that returns nothing).