Skip to content

refactor: make modules_mapping a regular rule #578

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

Merged
merged 4 commits into from
Jan 5, 2022

Conversation

f0rmiga
Copy link
Member

@f0rmiga f0rmiga commented Dec 9, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

  • Does not include precompiled binaries, eg. .par files. See CONTRIBUTING.md for info
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What has changes

The current modules_mapping is a repository rule. This changeset moves it to be a regular rule, consuming the wheels from pip_install instead of re-downloading and building (when necessary) them twice.

Does this PR introduce a breaking change?

  • Yes
  • No

Since the Gazelle plugin is not contained in any release, I don't consider it to be a breaking change.

@kormide
Copy link
Contributor

kormide commented Dec 15, 2021

Was there a reason why modules_mapping was originally a repository rule rather than a rule rule?

@f0rmiga
Copy link
Member Author

f0rmiga commented Dec 15, 2021

@kormide In the early days, the modules mapping was considerably faster compared to depending on all the wheels from pip_install. It was important because we were generating it on the fly (not checked-in as part of the gazelle manifest like we do now). This is not true anymore.

@alexeagle alexeagle force-pushed the simplify-modules-mapping branch from 385a983 to 54bc393 Compare December 29, 2021 16:25
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
@corypaik
Copy link

I was working on this a bit earlier since the previous version didn't work with --find-links and thought it could make sense to generate a modules_mapping.json for each wheel individually. I've refactored what I had to work with this rule and drafted a change that runs the generator once per wheel then merges the result. It seems to address the issue of having to recompute the module mapping for all dependencies each time one is updated.

Not really sure of a good way to benchmark it beyond rough timings and checking for cached actions, but it seems like it should be more efficient. Could also combine the json merger with the yaml generator if having them separate adds too much overhead, but I wasn't sure if there was another use for the merged json file beyond making the yaml one. I pushed the changes here.

@alexeagle alexeagle merged commit b842276 into bazel-contrib:main Jan 5, 2022
@f0rmiga f0rmiga deleted the simplify-modules-mapping branch January 5, 2022 00:06
@f0rmiga
Copy link
Member Author

f0rmiga commented Jan 5, 2022

@corypaik - interesting approach. We have been using it on a large project and haven't felt the need to do this performance improvement since the testing to check whether the checked-in manifest is up to date or not doesn't require recomputing the whole file.

The most expensive part of updating the modules mapping is downloading and, in some cases, compiling native modules. The tree traversal to generate the mappings is usually super fast and I don't think the performance improvement would be noticeable?

@aignas
Copy link
Collaborator

aignas commented Jan 7, 2022

I think making this a simple rule also fixed #574 because the same fetch packages can be now used here. So thanks for this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants