Skip to content

perf: generate only used Platform API operations - #644

Merged
alongubkin merged 2 commits into
mainfrom
alon/alien-861-filter-platform-rust-client
Sep 18, 2026
Merged

alongubkin merged 2 commits into
mainfrom
alon/alien-861-filter-platform-rust-client

Conversation

@alongubkin

Copy link
Copy Markdown
Member

Summary

  • generate the Platform Rust client from the 58 operations used by Alien instead of all 229 operations
  • retain transitively reachable components, discriminator mappings, path metadata, and security schemes
  • preserve the complete published SDK behind the default full-api feature
  • normalize uniquely matching nullable enum copies to named components so Progenitor does not emit duplicate Rust types
  • fail generation on missing operations, duplicate operation IDs, unresolved component references, or more than 600,000 filtered generated lines

Impact

  • generated Rust: 1,398,184 -> 534,989 lines (-61.7%)
  • generated Rust size: about 56 MB -> 22.2 MB (about -60.4%)
  • generated structs: 5,533 -> 2,003 (-63.8%)
  • generated enums: 3,663 -> 1,372 (-62.5%)
  • generated impls: 38,566 -> 14,187 (-63.2%)
  • Platform check unit: 326.5s baseline -> 35.4s observed
  • Platform build script: 30.1s baseline -> 7.2s observed
  • empty-target cargo check -p alien-cli --timings: 7m13s baseline -> 2m34s observed

The timing runs used empty Cargo target directories on the same machine but were recorded under different system load and filesystem-cache conditions. The generated-source reduction is deterministic; timing ratios are observed rather than a perfectly controlled attribution.

Validation

  • cargo check -p alien-cli
  • cargo test -p alien-platform-api --no-default-features --features rustls
  • cargo test -p alien-platform-api
  • generated full SDK still exposes all 229 operations
  • synthetic coverage for transitive references, cycles, discriminator mappings, path metadata, security schemes, missing/duplicate operations, unresolved references, and nullable enum normalization

Linear: ALIEN-861

@greptile-apps

greptile-apps Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previously reported missing build module is now included in the published crate.

Fix All in CodexFindings

  1. P1 Build Module Missing From Package ▶
Fix with agent prompt
### Issue 1
client-sdks/platform/rust/build.rs:3-4
The published crate includes only `build.rs`, `src/**/*`, and `openapi.json`, but this code now unconditionally loads `build/openapi_filter.rs`. Because that module will be missing from the crate archive, builds from crates.io or `cargo package` will fail. Add the new build source to the package include list.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR reduces the generated Rust Platform API client to operations used by Alien while preserving the complete SDK through the default full-api feature.

  • Filters the OpenAPI document to required operations and transitively reachable components.
  • Preserves path metadata, security schemes, discriminator mappings, and nullable enum compatibility.
  • Adds validation for malformed specifications and excessive generated output.
  • Includes build/**/* in the published crate, fixing the previously reported packaging failure.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Platform OpenAPI specification] --> B{full-api enabled?}
    B -->|Yes| C[Normalize complete specification]
    B -->|No| D[Retain required operations]
    D --> E[Discover transitively reachable components]
    E --> F[Preserve metadata and security schemes]
    F --> G[Normalize nullable enum copies]
    C --> H[Progenitor]
    G --> H
    H --> I[Generated Rust client]
    I --> J{Filtered output within line limit?}
    J -->|Yes or full-api| K[Compile SDK]
    J -->|No| L[Fail generation]
Loading

Reviews (2) · Last reviewed commit: "fix: include Platform API build support ..."

Comment thread client-sdks/platform/rust/build.rs
@alongubkin

Copy link
Copy Markdown
Member Author

@greptileai The P1 packaging finding is fixed: the crate include list now contains build/**/*, and cargo package -p alien-platform-api --list --allow-dirty confirms build/openapi_filter.rs is present. Please re-review.

@alongubkin
alongubkin force-pushed the alon/alien-861-filter-platform-rust-client branch from e08c465 to 87286d1 Compare September 17, 2026 23:27
@alongubkin
alongubkin enabled auto-merge (squash) September 17, 2026 23:57
@alongubkin
alongubkin force-pushed the alon/alien-861-filter-platform-rust-client branch from 87286d1 to 848a198 Compare September 18, 2026 00:04
@alongubkin
alongubkin merged commit d653999 into main Sep 18, 2026
21 checks passed
@alongubkin
alongubkin deleted the alon/alien-861-filter-platform-rust-client branch September 18, 2026 00:33
alongubkin added a commit that referenced this pull request Sep 18, 2026
## Summary

- give exact repeated anonymous object schemas deterministic component
identity before filtered Platform Rust generation
- reuse unique existing components and fail on generated-name or
content-hash collisions
- preserve the two anonymous schema families whose path-derived Rust
types are imported by handwritten Alien consumers
- tighten the filtered generated-source regression ceiling from 600,000
to 240,000 lines
- leave the default full 229-operation SDK unchanged

## Evidence

The filtered generated client shrinks:

| Metric | Before | After | Change |
| --- | ---: | ---: | ---: |
| Rust lines | 534,989 | 195,463 | -63.5% |
| Bytes | 22,198,092 | 7,342,952 | -66.9% |
| Structs | 2,003 | 1,125 | -43.8% |
| Enums | 1,372 | 518 | -62.2% |
| Impl blocks | 14,187 | 7,524 | -47.0% |

In an empty-target stacked `cargo check -p alien-cli --timings`:

- full CLI: 1m55s (previous stacked runs: 1m57.74s and 2m21.89s)
- Platform rustc unit: 12.9s (previous: 28.6-29.8s)
- Platform generator run: 1.9s (previous: 4.7-5.2s)
- warm filter edit through final CLI: 8.42s

Azure and native `aws-lc-sys` now dominate the cold critical path, so
the deterministic source and unit reductions are stronger attribution
than the smaller wall-time change.

## Validation

- `cargo test -p alien-platform-api --no-default-features --features
rustls`
- `cargo test -p alien-platform-api`
- `cargo check -p alien-cli`
- empty-target `cargo check -p alien-cli --timings`
- `git diff --check`

The first consumer check identified 13 imports of path-derived generated
types. The generator now protects exactly the two corresponding schema
families and fails if either pointer disappears; the complete CLI
compiles without call-site changes.

Depends on #644.

Linear: ALIEN-866
alongubkin added a commit that referenced this pull request Oct 5, 2026
## Problem
#644 made the Rust Platform API client generate only the operations
Alien calls. It kept the full client behind the default `full-api`
feature.

But `cargo build` or `cargo test` at the workspace root (and CI's `cargo
test --workspace` / `cargo nextest run --workspace`) selects
`alien-platform-api` as a package, so its default features apply.
Feature unification then gives every consumer the full unfiltered
client. In a cold CI test build:

| `alien-platform-api` part | Now | Filtered |
|---|---|---|
| lib | 156 s | 26 s |
| lib unit-test target | 147 s | 22 s |
| build script | 31 s | < 5 s |

## Change
- **`default = ["rustls"]`:** `full-api` is opt-in. SDK users who want
every operation add `features = ["full-api"]`. **Release note:** this
changes the crate's default features.
- **docs.rs metadata enables `full-api`,** so the published docs still
show the complete SDK.
- **New `Platform SDK full-api tests` step.** It runs `cargo test -p
alien-platform-api --features full-api`, so
`tests/command_registry_unavailable.rs` (`#![cfg(feature =
"full-api")]`) keeps running.
- In `ci-fast.yml`, it runs when `client-sdks/platform/rust/**`,
`Cargo.toml` or `Cargo.lock` change, or on manual runs.
  - In `ci-fork.yml`, it runs on every fork PR.

## Measured
Cold `cargo test --workspace --features
alien-manager/openapi,alien-bindings/platform-sdk --no-run` on
`depot-ubuntu-24.04-arm-8`, CI settings, 3 runs each:

| | Wall | CPU (user) |
|---|---|---|
| main | 388, 398, 407 s | ~1,790 s |
| this change | **301, 317, 318 s** | ~1,523 s |

That's about −22% on the build part of the `Rust crates` job, and the
same for any workspace-root build locally. All test targets compile with
the filtered client.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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