Skip to content

perf: shrink libcpex_ffi and harden cedar against small host stacks - #69

Merged
araujof merged 1 commit into
devfrom
feat/ffi_optimization
Jun 15, 2026
Merged

araujof merged 1 commit into
devfrom
feat/ffi_optimization

Conversation

@araujof

@araujof araujof commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Size-first release profile and a leaner tokio floor cut the statically linked FFI footprint, and the cedar dispatch is made host-stack-agnostic so musl-based hosts (Alpine) stop hitting Cedar's stack guard.

Changes

  • Add [profile.release]: opt-level="z", lto=true, codegen-units=1, strip=true. libcpex_ffi.a links statically into host binaries, so this flows into their image size; a representative statically-linked consumer shrank ~21%. panic="abort" is intentionally not set (the FFI relies on catch_unwind at its #[no_mangle] boundary). No API/ABI change.
  • Trim the workspace tokio feature floor from ["full"] to ["rt","rt-multi-thread","sync","time","macros"] (the real union used by the crates); reqwest/hyper still union net/io where needed. Drops the unused fs/process/signal surface and the signal-hook-registry dep.
  • Wrap the cedar dispatch (parse + build_entities + is_authorized) in apl-pdp-cedar-direct in stacker::maybe_grow. cedar-policy aborts with 'recursion limit reached' when stacker::remaining_stack() is below its 100 KiB floor; musl's 128 KiB default thread stack trips it on inputs glibc handles fine. maybe_grow runs cedar on a fresh, large segment when the host stack is low (a no-op on glibc). stacker dedups with cedar's transitive pin, so no new crates. Adds a regression test that evaluates on a 128 KiB stack.

Tests

770 tests pass (cargo test --workspace).

Size-first release profile and a leaner tokio floor cut the statically
linked FFI footprint, and the cedar dispatch is made host-stack-agnostic
so musl-based hosts (Alpine) stop hitting Cedar's stack guard.

- Add [profile.release]: opt-level="z", lto=true, codegen-units=1,
  strip=true. libcpex_ffi.a links statically into host binaries, so this
  flows into their image size; a representative statically-linked consumer
  shrank ~21%. panic="abort" is intentionally not set (the FFI relies on
  catch_unwind at its #[no_mangle] boundary). No API/ABI change.
- Trim the workspace tokio feature floor from ["full"] to
  ["rt","rt-multi-thread","sync","time","macros"] (the real union used
  by the crates); reqwest/hyper still union net/io where needed. Drops the
  unused fs/process/signal surface and the signal-hook-registry dep.
- Wrap the cedar dispatch (parse + build_entities + is_authorized) in
  apl-pdp-cedar-direct in stacker::maybe_grow. cedar-policy aborts with
  'recursion limit reached' when stacker::remaining_stack() is below its
  100 KiB floor; musl's 128 KiB default thread stack trips it on inputs
  glibc handles fine. maybe_grow runs cedar on a fresh, large segment when
  the host stack is low (a no-op on glibc). stacker dedups with cedar's
  transitive pin, so no new crates. Adds a regression test that evaluates
  on a 128 KiB stack.

770 tests pass (cargo test --workspace).

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
@araujof araujof added this to the 0.2.0 milestone Jun 15, 2026
@araujof
araujof requested review from jonpspri and terylt as code owners June 15, 2026 00:31
@araujof araujof added this to CPEX Jun 15, 2026
@araujof araujof added bug Something isn't working enhancement New feature or request framework Rust Go labels Jun 15, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in CPEX Jun 15, 2026

@terylt terylt 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.

LGTM

@araujof
araujof merged commit 7bebb20 into dev Jun 15, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in CPEX Jun 15, 2026
@araujof
araujof deleted the feat/ffi_optimization branch June 15, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request framework Go Rust

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants