Skip to content

Build bundled Linux dependencies with -O2 - #18

Merged
excid3 merged 1 commit into
mainfrom
optimize-bundled-deps
Oct 14, 2026
Merged

excid3 merged 1 commit into
mainfrom
optimize-bundled-deps

Conversation

@excid3

@excid3 excid3 commented Oct 14, 2026

Copy link
Copy Markdown
Member

Summary

On Linux, dependency_build_env set CFLAGS to just -fPIC, which replaces each project's default optimization level. As a result libyaml, libffi, libxcrypt, zlib, OpenSSL, ncurses, and libedit were all compiled at -O0 in every series we ship.

Upstream measured bcrypt about 5.7x slower and zlib deflate about 4.7x slower than the official ruby Docker image. bcrypt is affected because the gem's crypt_ra calls resolve to the libxcrypt linked into ruby.

This puts -O2 ahead of any inherited CFLAGS/CXXFLAGS, so dependencies are optimized even when CFLAGS is set, while an explicit -O level in CFLAGS still wins. -fPIC stays last so it always applies.

Ported from jdx#64.

Notes

  • The series-level cflags in recipes/series.yml only feed Ruby's own configure, not the dependency builds, so this applies to old and new series alike.
  • bin/build-fingerprint covers libexec/package.rb, so the next release run will rebuild every version and target instead of skipping. That is intended: the current artifacts carry the unoptimized libraries.

On Linux, dependency_build_env set CFLAGS to just -fPIC, which replaces
each project's default optimization level, so libyaml, libffi,
libxcrypt, zlib, OpenSSL, ncurses, and libedit were all compiled at
-O0. Upstream measured bcrypt about 5.7x slower and zlib deflate about
4.7x slower than the official ruby Docker image; bcrypt is affected
because the gem's crypt_ra calls resolve to the libxcrypt linked into
ruby.

Put -O2 ahead of any inherited CFLAGS so dependencies are optimized
even when CFLAGS is set, while an explicit -O level in CFLAGS still
wins. -fPIC stays last so it always applies.

Ported from jdx#64.
@excid3
excid3 merged commit a0e5771 into main Oct 14, 2026
7 checks passed
@excid3
excid3 deleted the optimize-bundled-deps branch October 14, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant