Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate size of express_parser.so for Ruby 3.0, 3.1 #122

Closed
CAMOBAP opened this issue Jun 2, 2022 · 10 comments · Fixed by #123
Closed

Investigate size of express_parser.so for Ruby 3.0, 3.1 #122

CAMOBAP opened this issue Jun 2, 2022 · 10 comments · Fixed by #123
Assignees
Labels
enhancement New feature or request

Comments

@CAMOBAP
Copy link
Contributor

CAMOBAP commented Jun 2, 2022

Intro

During the investigation of docker image size in the scope of metanorma/metanorma-docker#147 I have found that size of express_parser.so for Ruby 3.0, 3.1 (21 MB) is 3 times more than express_parser.so for Ruby 2.7 (7.2 MB)

Questions

  1. Is there a potential to reduce the size of express_parser.so for Ruby 3.0, 3.1?
  2. If this is not possible maybe we can conditionally remove unnecessary binaries. For example if we install expressir gem for Ruby 3.1, can we remove 2.7 and 3.0 variants?
@ronaldtse ronaldtse added the question Further information is requested label Jun 2, 2022
@ronaldtse
Copy link
Contributor

@maxirmx can you help check? Thanks!

@maxirmx
Copy link
Contributor

maxirmx commented Jun 2, 2022

I will look at it

@maxirmx
Copy link
Contributor

maxirmx commented Jun 2, 2022

Is there a potential to reduce the size of express_parser.so for Ruby 3.0, 3.1?

There is some difference between ruby 2.x and ruby 3.x that causes linker to behave differently.
Furthermore, it happens on redhat-like distributions only (expressir employs rake-compiler-dock that uses manylinux image to create native gems). If I build on Ubuntu, 2.7 version is 21 Mb as well

I can look at it further but I was not able to develop any plan yet.

@CAMOBAP
Copy link
Contributor Author

CAMOBAP commented Jun 2, 2022

Is there a potential to reduce the size of express_parser.so for Ruby 3.0, 3.1?

There is some difference between ruby 2.x and ruby 3.x that causes linker to behave differently. Furthermore, it happens on redhat-like distributions only (expressir employs rake-compiler-dock that uses manylinux image to create native gems). If I build on Ubuntu, 2.7 version is 21 Mb as well

I can look at it further but I was not able to develop any plan yet.

BTW how do you think about the second question? I just checked several gems and neither of them implements such behavior. Maybe there are some obvious reasons why it's not possible?

@maxirmx
Copy link
Contributor

maxirmx commented Jun 2, 2022

If this is not possible maybe we can conditionally remove unnecessary binaries. For example if we install expressir gem for Ruby 3.1, can we remove 2.7 and 3.0 variants?

  • Expressir employs rake-compiler-dock to create native extensions
  • Rake-compiler-dock links libruby statically (I do not understand why, probably to ensure stable environment)
  • Since libruby is linked statically a separate binary is required for each Ruby API version
    Please refer to nokogiri that also employs rake-compiler-dock and has 4 binaries packaged

We can probably develop bundler plugin that will remove all extra binaries not only for expressir but for other gems as well

@maxirmx
Copy link
Contributor

maxirmx commented Jun 2, 2022

I have to say that there is something wrong with expressir linkage. It is not only this size issue but also Alpine issues (#106)
Other gems built with rake-compiler-dock are glibc-neutral. This is the positive side of static linking.

@ronaldtse
Copy link
Contributor

Thanks @maxirmx for the continued investigation!

@maxirmx
Copy link
Contributor

maxirmx commented Jun 19, 2022

It looks like we can have only two versions of the library packed - 2.x and 3.x Ruby 2.7 cannot load 3.x library and 3.0 and 3.1 appear to be the same.
It will save 21Mb. @CAMOBAP does it make sense ?

@maxirmx
Copy link
Contributor

maxirmx commented Jun 19, 2022

I found the difference in compilation 2.x vs 3.x
I believe I will be able to create a version where both 2.x and 3.x files will be ~ 7.5 Mb

@maxirmx maxirmx added enhancement New feature or request and removed question Further information is requested labels Jun 19, 2022
@maxirmx maxirmx linked a pull request Jun 19, 2022 that will close this issue
@ronaldtse
Copy link
Contributor

Thank you @maxirmx !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants