rubyexegtk2ocra

Decrease load time for ruby app built on gtk2 and ocra


Have a small example pasted down which launches a system tray icon using gtk2 gem.

#!/usr/bin/env ruby
# encoding: UTF-8

require 'gtk2'

si=Gtk::StatusIcon.new
si.stock=Gtk::Stock::DIALOG_INFO
si.tooltip='StatusIcon'
si.signal_connect('activate'){|icon| icon.blinking=!(icon.blinking?)}

info=Gtk::ImageMenuItem.new(Gtk::Stock::INFO)
info.signal_connect('activate'){p "Embedded: #{si.embedded?}"; p "Visible: #{si.visible?}"; p "Blinking: #{si.blinking?}"}
quit=Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
quit.signal_connect('activate'){Gtk.main_quit}
menu=Gtk::Menu.new
menu.append(info)
menu.append(Gtk::SeparatorMenuItem.new)
menu.append(quit)
menu.show_all
si.signal_connect('popup-menu'){|tray, button, time| menu.popup(nil, nil, button, time)}

si.signal_connect('scroll-event'){|icon, event|
    modifier=event.state#A GdkModifierType indicating the state of modifier keys and mouse buttons
##Handle only control and shift key
    ctrl_shift=(Gdk::Window::CONTROL_MASK|Gdk::Window::SHIFT_MASK)
    mod=modifier&ctrl_shift
    case mod
    when 0
        print "(None)"
    when Gdk::Window::CONTROL_MASK
        print "Control+"
    when Gdk::Window::SHIFT_MASK
        print "Shift+"
    when (Gdk::Window::CONTROL_MASK|Gdk::Window::SHIFT_MASK)
        print "Control+Shift+"
    end
##Check for direction
    case event.direction
    when Gdk::EventScroll::UP
        print "up\n"
    when Gdk::EventScroll::DOWN
        print "down\n"
    end
}

exit if defined?(Ocra)
Gtk.main 

This works in a second if I run it as a ruby script i.e., ruby my_program.rb

But I would like to distribute it so I chose OCRA which builds me a exe file so that the user can run it without ruby or its packages installed.

So I run ocra my_program.rb --windows and it gives me a nice exe file called my_program.exe.

Problem : When I launch my_program.exe it takes 25 to 30 seconds to load the program.

The system tray icon takes 1 second and takes 30 times more to launch when packaged as a exe file.

Is there any possible way to decrease this load time. Thank you very much in advance.

EDIT: After a heads up I changed the ocra exe creation to ocra my_program.rb --windows --no-lzma. This solution saved me 10 seconds and now it is taking around 18-20 seconds for the program to load.

Can I optimize it more for a shorter load time? Please help.


Solution

  • Please see discussion on related topic here:

    http://programming.nullanswer.com/question/28323543

    It might be helpful.