halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
455 stars 86 forks source link

make set-java-home.bash work with an empty PROMPT_COMMAND #83

Closed strguntbr closed 4 years ago

strguntbr commented 4 years ago

set-java-home.bash is currently not working if the PROMPT_COMMANDis empty, because the resulting PROMPT_COMMANDwould be ; prompt_command.

strguntbr commented 4 years ago

I'm feeling like I learned something new today. My bash scripting knowledge is rather limited but the proposal seems to be a perfectly valid solution for the problem I'm experiencing.

However after having a closer look at the problem I think that setting the JAVA_HOME within the PROMPT_COMMAND is only a workaround that should be avoided, because the asdf which java is taking some time and now I have some delay after every command in bash, which is kind of annoying.

Nevertheless I think you proposal should be merged for now and I'm going to try understanding how asdf works to maybe come up with a better solution that does not rely on modifying PROMPT_COMMAND

halcyon commented 4 years ago

Thank you for your thoughtful response. I have resisted automatically setting JAVA_HOME until recently because I had experienced performance problems in the past. I would be interested to know how long asdf which java takes to run on your system. I would also be interested to know if this only happens when there are lots of JVMs installed and what other factors may be influencing it.

~$ time asdf which java
/home/ksm/.asdf/installs/java/adopt-openjdk-11.0.7+10_openj9-0.20.0/bin/java

real    0m0.127s
user    0m0.107s
sys     0m0.026s
~$ 

GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
strguntbr commented 4 years ago

On my system it takes between ~ 0.6s and 0.8s. I have only 2 JVMs installed, but I think the main problem on my system might be that I'm running Debian inside the Windows Subsystem for Linux. I guess that could be causing the bad performance on my system.

strguntbr@Galatea [debian]:/mnt/c/Users/strguntbr$ time asdf which java
/home/strguntbr/.asdf/installs/java/adopt-openjdk-11.0.6+10/bin/java

real    0m0.587s
user    0m0.016s
sys     0m0.563s
strguntbr@Galatea [debian]:/mnt/c/Users/strguntbr$ time asdf which java
/home/strguntbr/.asdf/installs/java/adopt-openjdk-11.0.6+10/bin/java

real    0m0.849s
user    0m0.078s
sys     0m0.531s
halcyon commented 4 years ago

Closed in favor of PR #89