Skip to content

feat(build): opt-in rusty_alloc global allocator feature - #5968

Merged
Hmbown merged 1 commit into
mainfrom
feat/rusty-alloc-optin-5872
Sep 7, 2026
Merged

feat(build): opt-in rusty_alloc global allocator feature#5968
Hmbown merged 1 commit into
mainfrom
feat/rusty-alloc-optin-5872

Conversation

@Hmbown

@Hmbown Hmbown commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Closes #5872

What

Adds rusty_alloc (the pure-Rust mimalloc v2.4.5 remake — no C compiler,
no build script on that path) as an off-by-default alternative global
allocator next to the existing mimalloc default, exactly as the issue asks.

  • Workspace pins rusty_alloc-api = "1.1.6". The issue's sketch pinned
    rusty_alloc but used rusty_alloc_api::RustyAlloc — the GlobalAlloc
    impl actually lives in the rusty_alloc-api crate (the project's
    documented "start here" surface), so that is the dependency; it pulls the
    rusty_alloc 1.1.6 core transitively at the same version. Verified on
    crates.io: both crates at 1.1.6, MIT, no further transitive deps.
  • rusty-alloc = ["dep:rusty_alloc-api"] feature added to codewhale-tui
    and codewhale-cli — the two crates whose src/main.rs owns the
    #[global_allocator] static.
  • Behind the feature the static maps to
    rusty_alloc_api::RustyAlloc (the README quick start); without it the
    mimalloc static compiles exactly as before behind
    #[cfg(not(feature = "rusty-alloc"))] — the default build is unchanged.
  • Doc line in docs/BUILD_PERFORMANCE.md (the only allocator-config doc
    hit), CHANGELOG [Unreleased] entry, sync-changelog.sh, and
    web/lib/changelog.generated.ts regenerated via
    web/scripts/derive-changelog.mjs (idempotent; keeps the web drift gate
    green).

Build with the feature

cargo build -p codewhale-tui --features rusty-alloc
cargo build -p codewhale-cli --features rusty-alloc

Gates (real counts)

Gate Result
cargo fmt --all clean
cargo check -p codewhale-tui --locked (default) clean, 2m31s (re-verified post-rebase, 7m20s)
cargo check -p codewhale-tui --locked --features rusty-alloc clean, 5m10s (re-verified post-rebase, 9m03s)
cargo check -p codewhale-cli --locked --features rusty-alloc clean, 2m04s
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings ... clean (exercises the new feature), 5m20s
cargo deny check advisories ok, bans ok, licenses ok, sources ok — no deny.toml entry needed (both new crates MIT, crates.io source)
cargo test -p codewhale-tui --lib --locked 11868 passed, 1 failed, 13 ignored (357s)

The one failure,
remote_control::tests::separate_predispatch_crashes_on_one_run_get_distinct_recovery_turn_ids,
passes on isolated rerun (1 passed / 0 failed) — a load/timing flake, not an
allocator effect: the lib test target does not compile the changed
src/main.rs. Reported rather than hidden.


Devin Review

Note

Low Risk
Default allocator and runtime behavior are unchanged; the swap only applies when the feature is explicitly enabled at compile time.

Overview
Adds an off-by-default rusty-alloc Cargo feature on codewhale-cli and codewhale-tui so builds can use the pure-Rust rusty_alloc global allocator (rusty_alloc-api 1.1.6) instead of mimalloc, avoiding a C toolchain on that path.

Each binary’s main.rs now selects the #[global_allocator] static with cfg(feature = "rusty-alloc"); default builds still use mimalloc unchanged. Workspace Cargo.toml/Cargo.lock pin the optional dependency, and changelog plus docs/BUILD_PERFORMANCE.md document how to enable it (cargo build -p codewhale-tui --features rusty-alloc).

Reviewed by Cursor Bugbot for commit 7fdc59f. Bugbot is set up for automated code reviews on this repo. Configure here.

Add an off-by-default `rusty-alloc` cargo feature to codewhale-tui and
codewhale-cli (#5872) that maps the `#[global_allocator]` static to
rusty_alloc (the pure-Rust mimalloc v2.4.5 remake — no C compiler, no
build script on that path) instead of the default mimalloc. The issue's
sketch pinned `rusty_alloc` and used `rusty_alloc_api::RustyAlloc`; the
GlobalAlloc impl actually lives in the `rusty_alloc-api` crate (the
crate's documented surface), so that is the dependency — it pulls the
rusty_alloc 1.1.6 core transitively at the same version. Default build is
unchanged: the mimalloc static compiles exactly as before behind
`#[cfg(not(feature = "rusty-alloc"))]`.

Build with: cargo build -p codewhale-tui --features rusty-alloc

Gates (worktree tmp/wt-5872-rusty-alloc, shared target dir):
- cargo fmt --all: clean
- cargo check -p codewhale-tui --locked: clean (2m31s)
- cargo check -p codewhale-tui --locked --features rusty-alloc: clean (5m10s)
- cargo check -p codewhale-cli --locked --features rusty-alloc: clean (2m04s)
- cargo clippy --workspace --all-targets --all-features --locked
  -- -D warnings -A clippy::uninlined_format_args -A clippy::too_many_arguments
  -A clippy::unnecessary_map_or: clean (5m20s)
- cargo deny check: advisories ok, bans ok, licenses ok, sources ok
  (both new crates are MIT; no deny.toml entry needed)
- cargo test -p codewhale-tui --lib --locked: 11868 passed, 1 failed,
  13 ignored (357s). The failure,
  remote_control::tests::separate_predispatch_crashes_on_one_run_get_distinct_recovery_turn_ids,
  passes in isolation on rerun (1 passed, 0 failed) and is unrelated to
  allocator wiring — the lib test target does not compile the changed
  src/main.rs. Reporting it as the one non-green result of the run.

CHANGELOG [Unreleased] entry + sync-changelog.sh + regenerated
web/lib/changelog.generated.ts (derive-changelog.mjs idempotent).

Signed-off-by: CodeWhale Bot <bot@codewhale.net>
Copilot AI lite review requested due to automatic review settings September 6, 2026 23:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T23:44:19.143712Z 7fdc59f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cursor

cursor Bot commented Sep 6, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_ff200bfe-7c1a-44b0-8681-540a9e2e7ed6)

@claude

claude Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Claude finished @Hmbown's task in 1m 6s —— View job


Review: opt-in rusty_alloc global allocator (#5872)

  • Gather context (PR body, changed files list)
  • Read diff against origin/main
  • Review Cargo.toml / Cargo.lock changes (dependency addition)
  • Review crates/cli/src/main.rs and crates/tui/src/main.rs allocator wiring
  • Review docs/CHANGELOG updates
  • Post final review

Summary: Small, well-scoped, off-by-default change. The #[cfg(not(feature = "rusty-alloc"))] / #[cfg(feature = "rusty-alloc")] split on the #[global_allocator] static in crates/cli/src/main.rs:1-10 and crates/tui/src/main.rs:1-10 is exhaustive and mutually exclusive, so exactly one static is compiled either way — no risk of a missing/duplicate #[global_allocator]. Feature wiring in both Cargo.tomls (dep:rusty_alloc-api, optional = true) matches the workspace's existing pattern for other optional deps. docs/BUILD_PERFORMANCE.md, both CHANGELOG.mds, and web/lib/changelog.generated.ts are consistent with each other.

No correctness, provider/model-routing, security, or duplication issues found:

  • No provider/model/route code touched — category 2 (EPIC v0.8.65 EPIC: Separate provider facts, model facts, offerings, and route resolution #2608 invariant) doesn't apply here.
  • No reuse/duplication introduced; the feature mirrors the existing mimalloc wiring rung-for-rung rather than adding a new abstraction (ponytail rung 2/6 respected).
  • Both new crates (rusty_alloc, rusty_alloc-api 1.1.6) are MIT-licensed per cargo deny check in the PR description, and deny.toml's skip list doesn't need a new entry since neither introduces a duplicate version of an existing dependency.

Minor, non-blocking notes:

  • The web/lib/changelog.generated.ts diff drops the "Sub-agents under delegated authority…" bullet from the displayed items array while itemCount goes 13→14. This looks correct given the file's own doc-comment ("items… clipped for the web; itemCount is the full count") — adding one new bullet at the top pushed the display window's last entry out. Regenerated deterministically via the documented script, so this is expected, not a regression.
  • PR body says "no further transitive deps" for the new crates, but Cargo.lock shows rusty_alloc transitively pulling in libc and windows-sys (both already present in the tree via other deps). Cosmetic inaccuracy in the description only, not a code issue.
  • No new tests were added, which is appropriate here — this is build/feature-flag config, not behavior, and the PR reports the existing default-path suite still passes (11868 passed / 1 known-flaky).

No changes requested.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment thread crates/cli/Cargo.toml
# mimalloc v2.4.5 remake — no C compiler, no build script) instead of the
# default mimalloc. Off by default; the default build is unchanged.
# Build with: cargo build -p codewhale-cli --features rusty-alloc
rusty-alloc = ["dep:rusty_alloc-api"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Rust allocator still requires C toolchain

Enabling rusty-alloc still compiles mandatory mimalloc. Its libmimalloc-sys dependency runs the C build this feature intends to avoid. Builds without a C toolchain still fail.

Prompt for agents
The rusty-alloc feature in crates/cli/Cargo.toml and crates/tui/Cargo.toml only enables rusty_alloc-api. Both crates retain mimalloc as an unconditional dependency, so Cargo still builds mimalloc and libmimalloc-sys, including its C build script, when rusty-alloc is selected. Redesign the allocator features and dependency wiring so a rusty_alloc build excludes mimalloc and its native build dependency while the ordinary default build continues using mimalloc. Update the documented build command if selecting the C-free path requires disabling a default allocator feature, and ensure invalid allocator feature combinations fail clearly.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread CHANGELOG.md
Comment on lines +51 to +56
- The `rusty-alloc` cargo feature on `codewhale-tui` and `codewhale-cli`
opts the binaries into the `rusty_alloc` global allocator (the mimalloc
v2.4.5 architecture remade in pure Rust — no C compiler or build script
on that path) instead of the default mimalloc. It is off by default and
the default build is unchanged; build with
`cargo build -p codewhale-tui --features rusty-alloc` (#5872).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Changelog edits bypass merge workflow

Repository policy reserves both changelogs for batched commits on main. Remove these branch changes and regenerate the derived web changelog.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fdc59f3ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/cli/Cargo.toml
# mimalloc v2.4.5 remake — no C compiler, no build script) instead of the
# default mimalloc. Off by default; the default build is unchanged.
# Build with: cargo build -p codewhale-cli --features rusty-alloc
rusty-alloc = ["dep:rusty_alloc-api"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Make mimalloc optional when selecting rusty-alloc

When rusty-alloc is selected, this feature only enables rusty_alloc-api; the unconditional mimalloc dependency at line 51 is still built, and Cargo.lock shows that it pulls libmimalloc-sys, whose dependency on cc invokes the native C build. As a result, the advertised build path for environments without a C toolchain can still fail before using RustyAlloc. Make the allocator dependencies mutually exclusive in both the CLI and TUI manifests while retaining mimalloc as the default.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

As wired, enabling --features rusty-alloc does not actually remove the mimalloc/libmimalloc-sys (C toolchain) build path due to unconditional dependencies and the codewhale-cli -> codewhale-tui -> mimalloc dependency chain.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an off-by-default rusty-alloc feature to let the codewhale-tui and codewhale-cli binaries use the pure-Rust rusty_alloc global allocator as an alternative to the current mimalloc default, with accompanying documentation and changelog updates.

Changes:

  • Introduces rusty-alloc Cargo features in crates/tui and crates/cli and switches #[global_allocator] via cfg(feature = "rusty-alloc").
  • Adds/pins rusty_alloc-api = 1.1.6 at the workspace level and wires it into the two binary crates.
  • Updates changelogs and build-performance documentation; regenerates the web changelog module.
File summaries
File Description
web/lib/changelog.generated.ts Adds an Unreleased changelog entry for the new allocator feature (generated output).
docs/BUILD_PERFORMANCE.md Documents the new allocator feature as a build/perf-related knob.
crates/tui/src/main.rs Selects the global allocator (mimalloc vs rusty_alloc_api::RustyAlloc) based on rusty-alloc.
crates/tui/CHANGELOG.md Adds an Unreleased entry describing the new rusty-alloc feature.
crates/tui/Cargo.toml Adds the rusty-alloc feature and an optional rusty_alloc-api dependency.
crates/cli/src/main.rs Selects the global allocator (mimalloc vs rusty_alloc_api::RustyAlloc) based on rusty-alloc.
crates/cli/Cargo.toml Adds the rusty-alloc feature and an optional rusty_alloc-api dependency.
CHANGELOG.md Adds an Unreleased entry describing the new rusty-alloc feature.
Cargo.toml Pins rusty_alloc-api = 1.1.6 in workspace dependencies.
Cargo.lock Records the new allocator crates (rusty_alloc, rusty_alloc-api) in the lockfile.
Review details

Suppressed comments (2)

crates/tui/Cargo.toml:112

  • mimalloc and rusty_alloc-api are both declared in [dependencies], so enabling --features rusty-alloc does not avoid compiling mimalloc/libmimalloc-sys (C toolchain via cc). If the feature is meant to remove the C toolchain requirement, gate these allocator dependencies so they’re mutually exclusive based on the feature.
shell-words = "1.1.1"
mimalloc.workspace = true
rusty_alloc-api = { workspace = true, optional = true }

crates/cli/Cargo.toml:52

  • Even with --features rusty-alloc, mimalloc is still an unconditional dependency here, so Cargo will still build libmimalloc-sys (which depends on cc) and require a C toolchain. To make the feature actually avoid C compilation, gate the allocator dependencies so mimalloc is only pulled when the feature is not enabled.
semver.workspace = true
tokio.workspace = true
mimalloc.workspace = true
rusty_alloc-api = { workspace = true, optional = true }
  • Files reviewed: 9/10 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cli/Cargo.toml
Comment on lines +14 to +18
# Opt-in global-allocator swap (#5872): build on rusty_alloc (the pure-Rust
# mimalloc v2.4.5 remake — no C compiler, no build script) instead of the
# default mimalloc. Off by default; the default build is unchanged.
# Build with: cargo build -p codewhale-cli --features rusty-alloc
rusty-alloc = ["dep:rusty_alloc-api"]
Comment thread crates/tui/Cargo.toml
Comment on lines +17 to +21
# Opt-in global-allocator swap (#5872): build on rusty_alloc (the pure-Rust
# mimalloc v2.4.5 remake — no C compiler, no build script) instead of the
# default mimalloc. Off by default; the default build is unchanged.
# Build with: cargo build -p codewhale-tui --features rusty-alloc
rusty-alloc = ["dep:rusty_alloc-api"]

@codewhale-agent codewhale-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Codewhale review

PR adds an off-by-default rusty-alloc feature to codewhale-tui and codewhale-cli, switching the global allocator in main.rs to rusty_alloc_api::RustyAlloc while keeping mimalloc as the default. The cfg switch itself is straightforward, but the feature does not actually remove mimalloc from the dependency graph, so the advertised no-C-toolchain goal is not met, and there is no automated coverage for the new feature.

Findings

  • [ERROR] mimalloc is still compiled when rusty-alloc is enabled, so the no-C-toolchain goal is not met (crates/cli/Cargo.toml)
    The PR documents cargo build -p codewhale-tui --features rusty-alloc as avoiding a C compiler/build script, but in both crates/cli/Cargo.toml and crates/tui/Cargo.toml the mimalloc dependency remains non-optional. Cargo builds the mimalloc crate (including its C build script) whenever the package is built, regardless of the rusty-alloc feature. The #[cfg(not(feature = "rusty-alloc"))] attribute only removes the #[global_allocator] static, not the dependency itself. The pure-Rust allocator path therefore still requires a C toolchain. Make mimalloc optional and feature-gate it so that the default build still selects mimalloc but a rusty-alloc build can skip it.
  • [WARNING] No automated CI or test coverage for the new rusty-alloc feature
    The PR lists manual cargo check/cargo build and clippy commands, but no CI configuration or test is added to keep this feature building. Since the feature is off by default, regressions in the feature-gated global allocator switch could land unnoticed.

Suggestions

  • crates/cli/Cargo.toml — Make mimalloc optional and add a default feature that enables it (for example default = ["mimalloc-allocator"] and mimalloc-allocator = ["dep:mimalloc"]), then mirror this in crates/tui/Cargo.toml. That keeps today's default build on mimalloc while allowing a true no-C-toolchain build with --no-default-features --features rusty-alloc.

Assessment

The cfg-based allocator selection is simple and correctly defaults to mimalloc, but the core value proposition of the feature—removing the C compiler from the build—is not delivered because mimalloc remains an unconditional dependency. This should be fixed before merging, and CI coverage for the feature should be added.


Advisory review by Codewhale (codewhale review --pr 5968 --post, head 7fdc59f3ae9c46d35a1bd4b6989f5271a23b5fac). Line-specific findings are also posted as inline review comments; mechanical fixes arrive as committable suggestions you can apply from the Files tab. CODEOWNERS approval still governs merge.

@Hmbown
Hmbown merged commit 1887bd0 into main Sep 7, 2026
39 of 40 checks passed
@Hmbown
Hmbown deleted the feat/rusty-alloc-optin-5872 branch September 7, 2026 02:33
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.

Add rusty_alloc as an opt-in feature next to mimalloc

2 participants