oneclick / rubyinstaller2

MSYS2 based RubyInstaller for Windows
https://rubyinstaller.org
BSD 3-Clause "New" or "Revised" License
654 stars 249 forks source link

Reducing the size of compiled extensions #130

Closed vais closed 5 years ago

vais commented 5 years ago

What problems are you experiencing?

I've just noticed that the size of compiled extensions (.so files) jumped an order of magnitude going from ruby 2.3.3 to 2.4.4. This seems to be caused by this change in rbconfig.rb:

-  CONFIG["debugflags"] = "-g"
+  CONFIG["debugflags"] = "-ggdb3"

Reverting this change makes .so files an order of magnitude smaller.

With CONFIG["debugflags"] = "-ggdb3" we get this:

C:\>ruby -e "puts Dir['C:/Ruby/rubyinstaller-2.4.4-1-x86/lib/ruby/gems/2.4.0/extensions/**/*.so'].map{|f| %(#{File.size(f)} #{File.basename(f)})}"
294682 jaro_winkler_ext.so
334430 puma_http11.so
475743 tiny_tds.so
459139 wdm_ext.so

With CONFIG["debugflags"] = "-g" we get this:

gem pristine --all --extensions
C:\>ruby -e "puts Dir['C:/Ruby/rubyinstaller-2.4.4-1-x86/lib/ruby/gems/2.4.0/extensions/**/*.so'].map{|f| %(#{File.size(f)} #{File.basename(f)})}"
20992 jaro_winkler_ext.so
38400 puma_http11.so
62464 tiny_tds.so
53248 wdm_ext.so

Should debugflags be changed in rubyinstaller2, or does this have to be done upstream? I'm concerned that getting this into Ruby trunk may be much more cumbersome given multiple platforms etc...

MSP-Greg commented 5 years ago

Is this do to CONFIG["debugflags"] or to strip not being used? I've got the same hash value, but the stripped puma file I have is approx. 45k...

vais commented 5 years ago

@MSP-Greg I am not aware of strip (how to use it or what it does). I'm simply setting CONFIG["debugflags"] back to -g (as it was in Ruby 2.3 days), and this alone cuts down the size of the .so files by a factor of 10. (Actually, the factor of 10 part is a little misleading - it's more like there is a static overhead of about 250 KB that gets cut, but since most files are small, this 250 KB overhead results in a factor of 10 difference.)

MSP-Greg commented 5 years ago

@vais

  1. strip can remove the info that using ggdb3 as a debug flag creates. See Ruby configure.ac:641

  2. I believe the files included with RI2 builds have been 'reduced' in size. The setting only affects compiling of extension gems.

  3. Unlikely that many Windows users will be using a gcc debugger. It could be removed from RbConfig with a patch.

vais commented 5 years ago

@MSP-Greg Thanks! Regarding point 3, I agree but not sure how to patch rbconfig.rb in the context of rubyinstaller2. Is there an example of something like this already being done in this project that I could use as a starting point to make a PR? (I.e. some other files in Ruby distribution getting patched/overwritten?)