JRuby is quick to show version number, slow to exit #530

Closed
charliesome opened this Issue Feb 9, 2013 · 7 comments

Projects

None yet

4 participants

@charliesome
Contributor

When I run ruby -v, the version string is printed to the terminal almost immediately.

However once the version string is printed, it sits there for a good second or so before exiting.

JRuby should exit immediately once it prints its version.

@ghost
ghost commented Feb 9, 2013

This might be environmental - it exits immediately for me (MacOS lion).

Make sure your shell environment is clean (no JRUBY_OPTS, RUBYOPT, etc).

@nirvdrum
Contributor
nirvdrum commented Feb 9, 2013

I'm seeing the same thing. This is on Ubuntu 12.10. I cleaned out my environment.

@BanzaiMan
Member

In the main loop, when we have processed the flags and decided to show the version string, we do it early: https://github.com/jruby/jruby/blob/1.7.3/src/org/jruby/Main.java#L241 but since we currently lack the smarts to determine if we need to actually do anything, we create a Ruby runtime (https://github.com/jruby/jruby/blob/1.7.3/src/org/jruby/Main.java#L262) anyway and do nothing with it. This, obviously, takes a long time (1 to 1.5 seconds on the wall clock).

If this really bothers people, it might be feasible to shortcut creating a Ruby runtime, but I don't yet know how simple it is to determine if this is desirable.

@BanzaiMan BanzaiMan added a commit that referenced this issue Mar 29, 2013
@BanzaiMan BanzaiMan Fix #530.
If no inline script (via '-e') or a script is given on the command-line,
do not create a Ruby runtime, but return immediately.
7233c83
@BanzaiMan
Member
$ time jruby -v                  
jruby 1.7.4.dev (1.9.3p392) 2013-03-28 7233c83 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_13-b20 [darwin-x86_64]
jruby -v  0.13s user 0.03s system 90% cpu 0.169 total
$ time jruby -v -e 'puts "hello"'
jruby 1.7.4.dev (1.9.3p392) 2013-03-28 7233c83 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_13-b20 [darwin-x86_64]
hello
jruby -v -e 'puts "hello"'  2.26s user 0.11s system 165% cpu 1.429 total

I will commit it to master if the build passes (just in case).

@BanzaiMan BanzaiMan added a commit that referenced this issue Mar 29, 2013
@BanzaiMan BanzaiMan Fix #530.
If no inline script (via '-e') or a script is given on the command-line,
do not create a Ruby runtime, but return immediately.
764cf23
@headius
Member
headius commented Mar 29, 2013

Some clarification...

jruby --version exits immediately, because as in MRI it does not ever run code:

ext-jruby-local ~/projects/jruby $ time jruby --version
jruby 1.7.4.dev (1.9.3p392) 2013-03-29 3859785 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_11-b21 [darwin-x86_64]

real    0m0.112s
user    0m0.090s
sys 0m0.022s

jruby -v is slower because it could potentially have stdin code if it doesn't have -e or a file to run. I'm not sure if there's a good way to determine if any code will be given at stdin.

However, I think MRI does not run stdin code until it reaches EOF, so perhaps before initializing the runtime we could attempt to read stdin to EOF and only boot if there's incoming code?

@charliesome
Contributor

@headius I'm not sure why this is problematic. Is it not just a matter of parsing options up front before deciding what to do?

MRI doesn't evaluate stdin code if you pass -v:

λ echo 'puts "hello world"' | ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.0]

However it does run code given in the -e option even if -v is present, so it's not as simple as just checking for a -v option:

λ ruby -v -e 'puts "hello world"'
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.0]
hello world
@headius
Member
headius commented Mar 29, 2013

Well I'll be darned...I thought for sure it ran the code. So apparently there's no way to pipe code and print out version as you can with a target script.

I guess this means we could basically just look for a target script, and if none is given and -v is passed, we call it even. I believe this is what @BanzaiMan intended to do with his commit, so we'll have to look deeper at what failed.

@charliesome Thanks for pointing this out!

@BanzaiMan BanzaiMan added a commit that closed this issue Mar 29, 2013
@BanzaiMan @headius BanzaiMan + headius Fix #530.
If no inline script (via '-e') or a script is given on the command-line,
do not create a Ruby runtime, but return immediately.
6005781
@BanzaiMan BanzaiMan closed this in 6005781 Mar 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment