# Suggestions to reduce binary size, make loading faster

**URL:** <https://www.ruby-forum.com/t/suggestions-to-reduce-binary-size-make-loading-faster/182901>\
**Category:** wxRuby\
**Created:** [February 4, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/suggestions-to-reduce-binary-size-make-loading-faster/182901 "2010-02-04T15:22:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![night\_stalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@night\_stalker](https://www.ruby-forum.com/u/night_stalker)\
**Post date:** [February 4, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/suggestions-to-reduce-binary-size-make-loading-faster/182901/1 "2010-02-04T15:22:16Z")

</div>

I found wxruby2.so in mingw release a bit large (18M), it is smaller  
(~15M) after stripping symbols. I learned this from  
[Reducing Executable Size - WxWiki](http://wiki.wxwidgets.org/Reducing_Executable_Size) . The command line  
is:

```
strip --strip-all wxruby2.so

```

But I don’t know whether there is a problem with stripping, at least my  
app still runs well with the stripped one.

* * *

The loading of wxruby is not very fast too(~ 1.3s on my machine). After  
a small profile, I found the following code in wx.rb the bottle-neck:

```
require 'wx/classes/evthandler.rb'
class_files = File.join( File.dirname( __FILE__ ), 'wx', 'classes',

```

‘\*.rb’)  
Dir.glob(class\_files) do | class\_file |  
require ‘wx/classes/’ + class\_file[/\w+.rb$/]  
end

A simple improvement is to make wx/classes/\*.rb into one.  
I wrote the following script, placed it under wx/, then run it to  
generate a new classes.rb containing most classes under wx/classes/

```
data = []
(Dir.glob('classes/*.rb') - [
  'classes/evthandler.rb',
  'classes/simplehelpprovider.rb',
  'classes/bitmap.rb'
]).each do |f|
  data.push File.read f
end
File.open 'classes.rb', 'w' do |f|
  f.puts data.join "\n"
end

```

Then I changed the classes loading section in wx.rb with:

```
require 'wx/classes/evthandler.rb'
require 'wx/classes.rb'

```

After this modification, the loading time seems shorter (reduced to ~  
0.4s on my machine).

---

<div class="post-metadata">

**Author:** ![night\_stalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@night\_stalker](https://www.ruby-forum.com/u/night_stalker)\
**Post date:** [February 8, 2010, 7:23pm UTC](https://www.ruby-forum.com/t/suggestions-to-reduce-binary-size-make-loading-faster/182901/2 "2010-02-08T19:23:17Z")

</div>

Hi Lui,

2010/2/4 Lui K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I found wxruby2.so in mingw release a bit large (18M), it is smaller  
> (~15M) after stripping symbols. I learned this from  
> [http://wiki.wxwidgets.org/Reducing\_Executable\_Size](http://wiki.wxwidgets.org/Reducing_Executable_Size) . The command line  
> is:
> 
> strip --strip-all wxruby2.so

We already use strip -x.  
But strip --strip-all seems to reduce the size a little more.  
I’ll try and see if there is no problem.

> A simple improvement is to make wx/classes/\*.rb into one.  
> I wrote the following script, placed it under wx/, then run it to  
> generate a new classes.rb containing most classes under wx/classes/

Interesting. I’ll take a look at it.

Cheers.  
Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![night\_stalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@night\_stalker](https://www.ruby-forum.com/u/night_stalker)\
**Post date:** [September 9, 2010, 10:09pm UTC](https://www.ruby-forum.com/t/suggestions-to-reduce-binary-size-make-loading-faster/182901/3 "2010-09-09T22:09:38Z")

</div>

Hi Lui,

2010/2/4 Lui K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> A simple improvement is to make wx/classes/\*.rb into one.  
> I wrote the following script, placed it under wx/, then run it to  
> generate a new classes.rb containing most classes under wx/classes/

Sorry for such a long delay …  
I’ve tested your suggestion and indeed the loading is a bit faster.  
But the improvement is only about 10-11% on my system according to a  
Benchmark.measure of a require ‘wx’.

I don’t know yet if it is worth adding a rake task for generating the  
classes.rb automatically even if I’ve already written it.

Does anybody has an opinion on the subject ?

Cheers.  
Chauk-Mean.
