Skip to content

add run_with_libfunc_profile + AotWithProgram pairing#1613

Open
avi-starkware wants to merge 2 commits into
avi/cairo_native/contract-executor-2from
avi/cairo_native/libfunc-profiling-2
Open

add run_with_libfunc_profile + AotWithProgram pairing#1613
avi-starkware wants to merge 2 commits into
avi/cairo_native/contract-executor-2from
avi/cairo_native/libfunc-profiling-2

Conversation

@avi-starkware

@avi-starkware avi-starkware commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Exposes the libfunc-profiling primitives that downstream consumers (e.g. the blockifier in starkware-libs/sequencer) currently maintain locally. The profile-collection pattern is callback-driven so the per-call key (tx hash, etc.) stays out of cairo-native.

Follows the no-enum design from #1612: there is no ContractExecutor dispatch enum; consumers pick an executor type per feature-flag build. Each step is its own commit so it can be reverted independently.

Changes

  • metadata::profiler::Profile is now pub (was a private type alias).
  • AotContractExecutor::run_with_libfunc_profile<H, F> (gated on with-libfunc-profiling, in new file src/executor/libfunc_profile.rs) wraps run: allocates a unique trace ID, points the executor's cairo_native__profiler__profile_id symbol at it, drains the resulting Profile after run returns, and hands it to a caller-supplied FnOnce(Profile) on success. A ProfilerGuard restores the previous trace ID and drops the LIBFUNC_PROFILE slot on both the success and unwind paths; a process-wide lock plus a thread-local depth counter make concurrent and nested (contract-calls-contract) profiled runs safe.
  • AotWithProgram { executor, program }: pairs an AOT executor with the Sierra program it was compiled from (needed to resolve libfunc samples). Exposes inherent methods:
    • run(...) — mirrors AotContractExecutor::run; routes through the profiling bookkeeping (the instrumented .so needs a live profile slot) and discards the profile.
    • run_with_profile(..., FnOnce(Profile, ArcProgram)) — hands the captured profile and the paired program to the callback.
  • pub type ArcProgram = Arc<Program> re-export so consumers can name the program handle without a direct cairo-lang-sierra dependency.

Commits (revert points)

  1. add run_with_libfunc_profile + AotWithProgram pairing — the profiling primitive.
  2. give AotWithProgram inherent run/run_with_profile methods — replaces the former enum dispatch; reverting this commit removes the interchangeable-call-site methods only.

Stack

  1. align sierra-emu StarknetSyscallHandler trait/types with cairo-native #1610 — trait alignment
  2. extract shared cairo-native-syscalls crate #1611 — extract shared crate
  3. add EmuContractExecutor (sierra-emu backend, interchangeable with AotContractExecutor) #1612EmuContractExecutor
  4. this PRrun_with_libfunc_profile + AotWithProgram

Test plan

  • cargo check (default features) clean
  • cargo check --features with-libfunc-profiling clean
  • cargo check --features sierra-emu,with-libfunc-profiling clean
  • cargo check --workspace --all-features clean
  • CI green

This change is Reviewable

@github-actions

github-actions Bot commented May 14, 2026

Copy link
Copy Markdown

✅ Code is now correctly formatted.

@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 98ed085 to 64c12b3 Compare May 14, 2026 12:26
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 474462f to 13381fa Compare May 14, 2026 12:26
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 64c12b3 to 7e5fcd7 Compare May 14, 2026 12:33
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch 2 times, most recently from b5e8d6b to 94bc246 Compare May 14, 2026 12:49

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 3 files and all commit messages.
Reviewable status: 3 of 4 files reviewed, all discussions resolved (waiting on TomerStarkware and Yoni-Starkware).

@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 7e5fcd7 to 4176352 Compare May 17, 2026 11:57
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 94bc246 to 24984b5 Compare May 17, 2026 11:57
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 4176352 to 7af0508 Compare May 17, 2026 12:08
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 24984b5 to 78bf3e4 Compare May 17, 2026 12:08
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 7af0508 to 38c5f2f Compare May 17, 2026 13:24
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 78bf3e4 to 5b13906 Compare May 17, 2026 13:24
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 38c5f2f to 81093b3 Compare May 17, 2026 13:27
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 5b13906 to de234b8 Compare May 17, 2026 13:28
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 81093b3 to 4f53f27 Compare May 17, 2026 13:58
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch 4 times, most recently from 74aab36 to d19f2ac Compare May 19, 2026 12:34
avi-starkware added a commit to starkware-libs/sequencer that referenced this pull request May 19, 2026
- Drop unused `NativeCompiledClassV1::new_from_emu`; it had no in-tree
  callers, and the sierra-emu construction path will be re-added when
  the benchmarking/replay tool that needs it lands.
- Revert `process_compilation_request`'s `.map(...)` shape to a direct
  `match`, moving `casm` into `NativeCompiledClassV1::new(_with_program)`
  in the `Ok` arm at zero cost instead of cloning it.
- Bump pinned cairo-native rev to pick up `cargo fmt` fix on
  starkware-libs/cairo_native#1613.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 4f53f27 to 6f77130 Compare May 20, 2026 09:43
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from d19f2ac to 60e4055 Compare May 20, 2026 09:46
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 6f77130 to aa4bf47 Compare May 28, 2026 14:56
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 60e4055 to a21f3f5 Compare May 28, 2026 14:57

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed all commit messages and made 1 comment.
Reviewable status: 1 of 4 files reviewed, 1 unresolved discussion (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).


src/executor.rs line 31 at r3 (raw file):

};
use bumpalo::Bump;
// Re-exported so libfunc-profiling consumers (e.g. blockifier) can refer to the

what kind of reference is expected?
if it is just as a value - since you only use is as Arc<Program> - export:
pub type ArcProgram = std::sync::Arc<cairo_lang_sierra::program::Program>;

avi-starkware added a commit to starkware-libs/sequencer that referenced this pull request May 28, 2026
- Drop unused `NativeCompiledClassV1::new_from_emu`; it had no in-tree
  callers, and the sierra-emu construction path will be re-added when
  the benchmarking/replay tool that needs it lands.
- Revert `process_compilation_request`'s `.map(...)` shape to a direct
  `match`, moving `casm` into `NativeCompiledClassV1::new(_with_program)`
  in the `Ok` arm at zero cost instead of cloning it.
- Bump pinned cairo-native rev to pick up `cargo fmt` fix on
  starkware-libs/cairo_native#1613.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from aa4bf47 to e6a4ad9 Compare May 31, 2026 12:03
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from a21f3f5 to be6cb3f Compare May 31, 2026 12:16
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from e6a4ad9 to 538f655 Compare May 31, 2026 13:33
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from be6cb3f to 8b6515b Compare May 31, 2026 13:34
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 538f655 to c8ed1f7 Compare June 1, 2026 11:26
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 8b6515b to 7f27488 Compare June 1, 2026 11:26
avi-starkware added a commit to starkware-libs/sequencer that referenced this pull request Jun 1, 2026
- Drop unused `NativeCompiledClassV1::new_from_emu`; it had no in-tree
  callers, and the sierra-emu construction path will be re-added when
  the benchmarking/replay tool that needs it lands.
- Revert `process_compilation_request`'s `.map(...)` shape to a direct
  `match`, moving `casm` into `NativeCompiledClassV1::new(_with_program)`
  in the `Ok` arm at zero cost instead of cloning it.
- Bump pinned cairo-native rev to pick up `cargo fmt` fix on
  starkware-libs/cairo_native#1613.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@avi-starkware avi-starkware left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@avi-starkware made 1 comment.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on orizi, TomerStarkware, and Yoni-Starkware).


src/executor.rs line 31 at r3 (raw file):

Previously, orizi wrote…

what kind of reference is expected?
if it is just as a value - since you only use is as Arc<Program> - export:
pub type ArcProgram = std::sync::Arc<cairo_lang_sierra::program::Program>;

Done.

@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 0b0a902 to 6640ce9 Compare July 5, 2026 08:04
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from c8ed1f7 to 90cd01f Compare July 5, 2026 08:04
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 6640ce9 to c7e5bcc Compare July 5, 2026 08:30
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 90cd01f to a1e3635 Compare July 5, 2026 09:00
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from c7e5bcc to 7107710 Compare July 5, 2026 09:00

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 5 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).


src/executor/contract_executor.rs line 150 at r5 (raw file):

    /// callers don't have to keep their own copy around just to resolve libfunc samples.
    /// For other variants this is identical to `run` and `on_profile` is never invoked.
    #[cfg(feature = "with-libfunc-profiling")]

following my response to the previous PR - seems to me this is basically the only interesting function.

@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 7107710 to 0f1975e Compare July 6, 2026 10:37
avi-starkware and others added 2 commits July 6, 2026 15:01
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
With the ContractExecutor enum gone, AotWithProgram exposes the same
run() shape as AotContractExecutor directly, plus a profile-capturing
run_with_profile(), so feature-flag builds can swap executor types
without call-site changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@avi-starkware avi-starkware force-pushed the avi/cairo_native/libfunc-profiling-2 branch from 0f1975e to 6184f7a Compare July 6, 2026 12:03
@avi-starkware avi-starkware changed the title add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor add run_with_libfunc_profile + AotWithProgram pairing Jul 6, 2026
avi-starkware added a commit to starkware-libs/sequencer that referenced this pull request Jul 6, 2026
- Drop unused `NativeCompiledClassV1::new_from_emu`; it had no in-tree
  callers, and the sierra-emu construction path will be re-added when
  the benchmarking/replay tool that needs it lands.
- Revert `process_compilation_request`'s `.map(...)` shape to a direct
  `match`, moving `casm` into `NativeCompiledClassV1::new(_with_program)`
  in the `Ok` arm at zero cost instead of cloning it.
- Bump pinned cairo-native rev to pick up `cargo fmt` fix on
  starkware-libs/cairo_native#1613.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avi-starkware

Copy link
Copy Markdown
Collaborator Author

src/executor/contract_executor.rs line 150 at r5 (raw file):

Previously, orizi wrote…

following my response to the previous PR - seems to me this is basically the only interesting function.

Following my response to your response - removed this file

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.

2 participants