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

Add libgmp for faster Integer calculations. #266

Merged
merged 2 commits into from Mar 1, 2019
Merged

Conversation

@lsb
Copy link
Contributor

@lsb lsb commented Feb 27, 2019

I was wondering why some large integer multiplications were taking a while, so I ran

$ docker run ruby:2.6 ruby -e 'puts Integer::GMP_VERSION'
-e:1:in `<main>': uninitialized constant Integer::GMP_VERSION (NameError)

and found that GMP wasn't included in the default images. Building these images gives me

$ docker run ruby:gmp-2.6 ruby -e 'puts Integer::GMP_VERSION'
GMP 6.1.2

For significantly large integers (on my machine) GMP is over 50x faster than Ruby's fallback Integer methods: https://github.com/ruby/ruby/blob/a2eb04f52dccb9b42404f8b133acb36b577e3b54/bignum.c#L2527

@lsb

This comment has been hidden.

@tianon
Copy link
Member

@tianon tianon commented Mar 1, 2019

Nice catch; I dug in and found ruby/ruby@83a0709, which led me to wonder if this was actually applicable enough to add to buildpack-deps which led me to find:

... and thus file docker-library/buildpack-deps#92. 👍

Loading

@tianon
Copy link
Member

@tianon tianon commented Mar 1, 2019

(but this is still applicable for -slim and -alpine variants, so I'll be pushing an update shortly after I finish a little testing to make sure it works on each)

Loading

@tianon tianon merged commit f2bdb4a into docker-library:master Mar 1, 2019
1 check passed
Loading
tianon added a commit to infosiftr/stackbrew that referenced this issue Mar 1, 2019
- `buildpack-deps`: `libgmp-dev` (docker-library/buildpack-deps#92)
- `docker`: 18.09.3
- `ghost`: 2.16.2
- `mariadb`: 10.4.3
- `mongo`: 3.6.11
- `openjdk`: 13-ea+10
- `rabbitmq`: 3.7.13-rc.2, `RABBITMQ_VM_MEMORY_HIGH_WATERMARK=0` valid (docker-library/rabbitmq#322)
- `ruby`: `libgmp` (docker-library/ruby#266)
abevoelker
Copy link

abevoelker commented on eae22dc Mar 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see libgmp3-dev got swapped out for libgmp-dev in the slim images. FWIW I had to install libgmp3-dev on the latest ruby:2.5-slim image to get the nokogiri gem to install correctly.

Loading

juusujanar
Copy link

juusujanar commented on eae22dc Mar 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ran into same issue, nokogiri could not build it's native extensions (alpine and slim). Error was
/usr/bin/ld: cannot find -lgmp. libgmp3-dev helped on slim, but haven't discovered a solution for alpine yet.

Loading

petercv
Copy link

petercv commented on eae22dc Mar 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem here with installing spaceship which depends on fastlane which indirectly depends on the unf_ext gem. So more people might run into issues.

Loading

abevoelker
Copy link

abevoelker commented on eae22dc Mar 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if I was doing something wrong at first, but since others are having the same/similar issue, I opened #267 for this.

Loading

guizmaii

This comment has been hidden.

Loading

tareksamni
Copy link

tareksamni commented on eae22dc Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you came here because of Nokogiri installation is throwing an error:

Installing nokogiri 1.9.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

That's probably because of It seems that gmp-dev somehow didn't make it into the image. It is added to the ruby-builddeps it gets cleaned up by the apk add --no-cache --virtual .ruby-builddeps.

To fix it:

apk add --no-cache gmp-dev

Loading

tianon
Copy link
Member

tianon commented on eae22dc Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the discussion over to #267 to keep it all in one place.

Loading

@maxbrunet
Copy link

@maxbrunet maxbrunet commented Mar 3, 2019

@juusujanar I got the issue with nokogiri on alpine and fixed it by installing gmp-dev.

Loading

maxbrunet added a commit to maxbrunet/lofocats_api that referenced this issue Mar 3, 2019
maxbrunet added a commit to maxbrunet/lofocats_ui that referenced this issue Mar 3, 2019
maxbrunet added a commit to maxbrunet/lofocats_api that referenced this issue Mar 3, 2019
maxbrunet added a commit to maxbrunet/lofocats_ui that referenced this issue Mar 3, 2019
@ALandscheidt
Copy link

@ALandscheidt ALandscheidt commented Mar 4, 2019

jaro_winkler can't build on ruby:2.4.5-slim-stretch. Add libgmp-dev fixed it.

Loading

@springerigor
Copy link

@springerigor springerigor commented Mar 4, 2019

Since this PR was merged libgmp-dev is removed by apt-get purge command. As a result it is not available during runtime and some Ruby gems depends on it (like well-known nokogiri).

To solve the issue you should install it by yourself (apt get libgmp-dev).

I tested it with Ruby 2.5.3 & Nokogiri 1.8.4 and the described approach solved the issue.

Loading

@tianon
Copy link
Member

@tianon tianon commented Mar 4, 2019

See #267 for where this issue is being discussed further.

Loading

@docker-library docker-library locked and limited conversation to collaborators Mar 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants