Skip to content

add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor#1613

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

add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor#1613
avi-starkware wants to merge 1 commit into
avi/cairo_native/contract-executor-2from
avi/cairo_native/libfunc-profiling-2

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

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

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.

Replaces #1599 / #1609.

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). A ProfilerGuard restores the previous trace ID and drops the LIBFUNC_PROFILE slot on both the success and unwind paths.
  • ContractExecutor::AotWithProgram(AotWithProgram { executor, program }) is a new variant that bundles an AOT executor with the Sierra program it was built from. From<AotWithProgram> is provided.
  • ContractExecutor::run dispatches the new variant via run_with_libfunc_profile with a no-op profile callback.
  • ContractExecutor::run_with_profile<H, F> is the profile-capturing counterpart of run; for non-AotWithProgram variants it falls through to run (callback never fires).

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 ContractExecutor dispatch enum (Aot + Emu) #1612ContractExecutor (supersedes add ContractExecutor dispatch enum (Aot + Emu) #1598 / add ContractExecutor dispatch enum (Aot + Emu) #1608)
  4. this PRrun_with_libfunc_profile + AotWithProgram (supersedes add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1599 / add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1609)

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
Copy link
Copy Markdown

github-actions Bot commented May 14, 2026

✅ 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
Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

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
…cutor

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.

- 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 with the bookkeeping the runtime needs:
    1. Acquires a process-wide PROFILE_LOCK so concurrent profile calls
       serialize on the global trace-id symbol. The lock is recovered
       if poisoned.
    2. Looks up the profile-id symbol before touching any global state.
       Absent symbol -> typed Error::UnexpectedValue rather than panic.
    3. Allocates a trace ID, inserts a slot in LIBFUNC_PROFILE, points
       the global at the new ID.
    4. Calls run; on success drains the slot and hands the Profile to
       on_profile. On failure the callback is not invoked.
    5. A ProfilerGuard restores the previous trace ID on success and
       unwind.
- ContractExecutor::AotWithProgram(AotWithProgram { executor, program })
  is a new variant that bundles an AOT executor with the Sierra program
  it was built from. From<AotWithProgram> is provided.
- ContractExecutor::run dispatches the new variant via
  run_with_libfunc_profile with a no-op profile callback.
- ContractExecutor::run_with_profile<H, F> is the profile-capturing
  counterpart of run; for non-AotWithProgram variants it falls through
  to run (callback never fires).

Co-Authored-By: Claude Opus 4.7 (1M context) <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.

2 participants