Skip to content

build: use ThinLTO for release binaries#23710

Merged
anp-oai merged 3 commits into
mainfrom
codex/build-times-question-mark
Jun 4, 2026
Merged

build: use ThinLTO for release binaries#23710
anp-oai merged 3 commits into
mainfrom
codex/build-times-question-mark

Conversation

@anp-oai
Copy link
Copy Markdown
Collaborator

@anp-oai anp-oai commented May 20, 2026

Why

Fat LTO makes release builds substantially slower without providing enough measured runtime benefit to justify the release CI long pole. The build-profile investigation found that keeping Cargo's default release opt-level=3 and switching from fat LTO to ThinLTO (3/thin/1) reduced a clean codex-cli release build from 2073.893 seconds to 1243.172 seconds, a 40.06% improvement.

The resulting binary increased from 196.7 MiB to 211.8 MiB (+7.63%). Measured runtime changes were small: the worst image workload median was +0.86% and app-server startup was +0.31% relative to fat LTO. ThinLTO retains cross-crate optimization while avoiding most of the fat-LTO build cost.

This deliberately avoids global size optimization: final-executable testing showed a substantial regression on the image request path, which is expected to become more important as image usage grows.

What changed

  • Set the workspace release profile to lto = "thin", retaining Cargo's default release opt-level=3.
  • Remove release and CI workflow-specific LTO overrides so release-profile builds consistently use the workspace setting.
  • Remove the now-unused Windows release workflow input and related diagnostic output.

Validation

  • Confirmed the release profile parses with cargo metadata --no-deps --format-version 1.
  • CI validates release builds across the supported target matrix.

@anp-oai anp-oai force-pushed the codex/build-times-question-mark branch 2 times, most recently from 64a4717 to b1f2a98 Compare May 21, 2026 21:33
@sozforex
Copy link
Copy Markdown

sozforex commented May 21, 2026

would be interesting to see a comparison of max RAM use during compilation and some kind of runtime cpu load comparison between resulting binaries.

@anp-oai anp-oai force-pushed the codex/build-times-question-mark branch from b1f2a98 to 0f79266 Compare June 3, 2026 21:23
@anp-oai anp-oai changed the title build: Optimize for size and use ThinLTO for release binaries. build: disable LTO for release binaries Jun 3, 2026
@anp-oai anp-oai marked this pull request as ready for review June 3, 2026 21:27
anp-oai added a commit that referenced this pull request Jun 3, 2026
## Why

PR descriptions can be visible outside the context used to generate
them. In #23710, a generated description referenced an internal
document, showing that the skill needs an explicit guardrail against
exposing confidential context.

## What changed

- Updated the `codex-pr-body` guidance to prohibit confidential
references, including codenames and OpenAI-internal URLs.
Comment thread codex-rs/Cargo.toml Outdated
@bolinfest bolinfest self-requested a review June 4, 2026 17:57
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

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

Approving assuming this changes to lto = "thin" as discussed in Slack, as it's a more conservative change an the opt level we are currently using in our alphas.

@anp-oai anp-oai force-pushed the codex/build-times-question-mark branch from 0f79266 to ca53c6c Compare June 4, 2026 17:58
@anp-oai anp-oai requested a review from a team as a code owner June 4, 2026 17:58
@anp-oai anp-oai changed the title build: disable LTO for release binaries build: use ThinLTO for release binaries Jun 4, 2026
@anp-oai
Copy link
Copy Markdown
Collaborator Author

anp-oai commented Jun 4, 2026

Switched to ThinLTO per slack discussion, waiting for CI before merging

anp-oai added 3 commits June 4, 2026 12:50
After running a variety of Linux release builds of the CLI binary[0]
it seems that this configuration is a good sweet spot when trading
off between runtime performance, binary size, and build times.

From git history it seems that using LTO was originally motivated
by binary size reductions (see linked gist) but we can get much
smaller binaries with much faster links if we switch from the
default release optimization to asking LLVM to optimize aggressively
for size.

If our only priorities were build times and binary size, switching
from opt-level 3 to z without any LTO might be the sweet spot since
it's quite fast to build (again see linked gist). However ThinLTO is
quite fast to build and leaves less performance on the table.

Locally this cuts the time to build a release binary by 2/3 and the
resulting binary is quite usable.

[0] https://gist.github.com/anp/71820f253d4528f313171a57b3b895e7
Follow-up runtime measurements showed that optimizing globally for size significantly slows the final executable image path. Keep Cargo's default release opt-level of 3 and use ThinLTO for a lower-risk release build-time improvement that preserves cross-crate optimization.
@anp-oai anp-oai force-pushed the codex/build-times-question-mark branch from ca53c6c to 1a6c84a Compare June 4, 2026 19:55
@anp-oai anp-oai enabled auto-merge (squash) June 4, 2026 20:02
@anp-oai anp-oai merged commit f97d5c3 into main Jun 4, 2026
46 checks passed
@anp-oai anp-oai deleted the codex/build-times-question-mark branch June 4, 2026 20:07
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants