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

perf: optimize update_plugin function #1665

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Dabolus
Copy link

@Dabolus Dabolus commented Oct 11, 2023

Summary

This PR improves the performance of the update_plugin function by only contacting remote if/when needed.
It does so by making two main changes:

  1. Only running the ls-remote when the third parameter to the function is not provided, as before it was always run and its result was ignored if the third parameter was there;
  2. Avoiding to fetch remote unless needed, i.e. not fetching if the provided gitref is a commit and is already available locally.

This gives a big performance boost, especially when on a slow internet connection, and removes the dependency on remote when it's not needed. For example, the change is very noticeable when re-running add-all while using asdf-plugin-manager.

Benchmarks

With the original implementation:

  • asdf plugin update <plugin-name>: ≈3.5s ← remote contacted twice
  • asdf plugin update <plugin-name> <branch>: ≈3.5s ← remote contacted twice
  • asdf plugin update <plugin-name> <new gitref>: ≈3.5s ← remote contacted twice
  • asdf plugin update <plugin-name> <existing gitref>: ≈3.5s ← remote contacted twice

With these changes:

  • asdf plugin update <plugin-name>: ≈3.5s ← remote contacted twice
  • asdf plugin update <plugin-name> <branch>: ≈1.7s ← remote contacted once
  • asdf plugin update <plugin-name> <new gitref>: ≈1.7s ← remote contacted once
  • asdf plugin update <plugin-name> <existing gitref>: ≈0.1s ← remote not contacted at all

Note: these benchmarks are from my machine with my internet connection. Results may vary a lot depending on the internet connection of the device running them.

@Dabolus Dabolus requested a review from a team as a code owner October 11, 2023 07:23
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.

2 participants