Eliminate Startup Delay?

I have been very tempted recently to give up JRuby in favour of Python.
Part of the reason is that I have been dabbling with Arduinos and the
Arduino community is more likely to be familiar with Python. And the
other part is the JRuby startup delay which is painfully obvious after
using Python for an hour.

Then it occurred to me that the startup delay could be avoided by
preventing JRuby from exiting when a program finished.

This short code is a first crude attempt to achieve that and it seems to
work. Indeed it runs the short test program so fast that I lose track of
whether I have pressed return. And it seems to catch load errors, syntax
errors, runtime errors and java errors (in a much larger program that I

I have little doubt that a more experienced JRuby programmer will see
scope for many improvements.

It would be nice if every possible exception could be trapped with a
single RESCUE clause - but I don’t know how to do that.



def runScript
          # load is used as require would only load the script once
        load $scriptName
          # assumes script contains a method called scriptStart
    rescue ScriptError       # catches load and syntax errors
        puts "SCRIPT ERROR A"
        puts $!
    rescue NativeException   # catches Java errors
        puts "SCRIPT ERROR B"
        puts $!
    rescue                     # catches runtime errors
        puts "SCRIPT ERROR C"
        puts $!

puts "Starting ScriptRunner"

$scriptName = "./test.rb"

while true
  puts "Press Return"
  xxx = gets
  puts "Done"



def scriptStart
  puts "Hey - here is testing"
  xxx = 8 / 1
  puts xxx

Hello Robin,

Your idea is in theory a good one, and it has been implemented in a
couple of different ways as Nailgun and Drip
https://github.com/jruby/jruby/wiki/Improving-startup-time. Your
particular proposed solution, in Ruby, has additional drawbacks in that
each script isnt going to get a fresh interpreter state is it? Any
modules, classes, global variables, threads, monkey patches etc created
in one script will hang around for the next one.


Chris S. wrote in post #1158047:

modules, classes, global variables, threads, monkey patches etc created
in one script will hang around for the next one.

Agreed. I wasn’t thinking of using this idea to run several different
programs but, rather, to be able to re-run the same program quickly
during development. For example to provide an immediate response to
stupid typos.

I haven’t tried, but I guess you could start a different version of
ScriptRunner for each program you want to work with. That should keep
the variables etc separate.

The startup delay is much less relevant for a finished program that is
only started once per day, and my idea would have no role there.

I only came across Drip yesterday and it didn’t seem to have any impact
on startup delay. I seem to remember trying Nailgun a long time ago and
it wouldn’t work with whatever I was trying.