-
-
Notifications
You must be signed in to change notification settings - Fork 644
improve speed of scripts #1439
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 speed of scripts #1439
Conversation
|
Hi @Subarctic2796, Unfortunately, we won't be making broad sweeping changes to the entire CLI so close to its retirement. This piece of software has been tried and tested over many years and has very few issues due to small incremental fixes and improvements from many contributors. After all, in the words of Thomas Bertram, "If it ain't broke, don't fix it" 🙂
Can you be more specific about your vast improvements? Can you provide your benchmarks? When I source the Lastly, I noticed that all checks have failed on your build, which immediately decreases my confidence in the PR. In the future, please reach out to us on our community Discord server as described in the contributing guidelines linked below. Having an upfront discussion about such big change will avoid disappointment when your PR is closed on submission. |
|
Hi sorry about this PR. I realised to late that the changes I made were causing the tests to fail, and I ran out of time yesterday to fix them. So I completely understand why you closed the PR. All I was trying to do was improve the speed of the init script as it causes my shell to start up slowly. So I am sorry for this waste of time. So I have deleted that fork. That being said eventhough the native rewrite is happening, it will still need an init script to set everything up. I am more than happy to help speed it up if you want. But I completely understand it you don't want my help, as I may be sounding arrogant, which isn't my intention. I love what you have done for the community and I just wanted to help. You are welcome to stop reading now. Change the if [ -z "$SDKMAN_CANDIDATES_API" ]; then
export SDKMAN_CANDIDATES_API="https://api.sdkman.io/2"
fiBecome: export SDKMAN_CANDIDATES_API=${SDKMAN_CANDIDATES_API:-"https://api.sdkman.io/2"}It does the same thing but it is faster for Remove the cat in SDKMAN_PLATFORM="$(cat "${SDKMAN_DIR}/var/platform")"And change it to SDKMAN_PLATFORM="$(<${SDKMAN_DIR}/var/platform")"I am not sure why you do it here as you do it the way bash recommends here SDKMAN_CANDIDATES_CSV=$(<"$SDKMAN_CANDIDATES_CACHE")So thats just a bit weird. When you are looking for the scripts instead of using scripts=($(find "${SDKMAN_DIR}/src" "${SDKMAN_DIR}/ext" -type f -name 'sdkman-*.sh'))
for f in "${scripts[@]}"; do
source "$f"
donebecomes for f in $SDKMAN_DIR/{src,ext}/sdkman-*.sh; do
source "$f"
doneThe only issue with this is that if there are no scripts in for f in $SDKMAN_DIR/{src,ext}/sdkman-*.sh(N); do
source "$f"
doneInstead of doing this for candidate_name in "${SDKMAN_CANDIDATES[@]}"; do
candidate_dir="${SDKMAN_CANDIDATES_DIR}/${candidate_name}/current"
candidate_dir="$candidate_name/current"
if [[ -h "$candidate_dir" || -d "${candidate_dir}" ]]; then
__sdkman_export_candidate_home "$candidate_name" "$candidate_dir"
__sdkman_prepend_candidate_to_path "$candidate_dir"
fi
doneto add the candidates to they path, this does way to many unnessasary iterations and pointless function calls for candidate_name in $SDKMAN_CANDIDATES_DIR/*; do
candidate_dir="$candidate_name/current"
if [[ -h "$candidate_dir" || -d "${candidate_dir}" ]]; then
candidate_name="${candidate_name##*/}"
[[ -z "${candidate_name:u}_HOME}" ]] && export "${candidate_name:u}_HOME"="$candidate_dir"
if [[ -d "${candidate_dir}/bin" ]]; then
candidate_dir="$candidate_dir/bin"
fi
[[ "$PATH" == *"$candidate_dir"* ]] || PATH="${candidate_dir}:${PATH}"
fi
doneAlthough this has the same issue with If you want any explanations I would be happy to explain. And if you want me to make these changes I would be happy to make a new PR that only makes these changes and I would make sure that the tests pass. |
|
@Subarctic2796 I'm happy to take on board some of these changes you noted above in new PRs that only touch the affected areas in the init script. We will only consider merging if you open small PRs for the individual pieces of work and if all the checks pass. |
|
Awesome thanks I will do that |
Fixes #XXX
Hi.
I know I did not link to any open issues. But I still think that this is an important change.
Basically I vastly improved the execution speed of the scripts. I do know that most of the functions in the scripts are being rewritten to the native versions, with that in mind I still think it is important as it also vastly improves the start up time of a shell that is using sdkman. It also uses many more native bash features. I also changed some of the formating of the scripts if that is okay.
Most of the changes I made are commented or are using the same technique as other changes. If you are not sure why I changed something I am more than happy to explain what I did.