Skip to content

arena for dict#1616

Merged
TomerStarkware merged 1 commit into
mainfrom
tomer/arena_dict
May 19, 2026
Merged

arena for dict#1616
TomerStarkware merged 1 commit into
mainfrom
tomer/arena_dict

Conversation

@TomerStarkware

@TomerStarkware TomerStarkware commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Move felt252_dict storage to the per-execution arena

Closes #NA

Moves FeltDict allocation off the system heap and onto the per-execution Bump arena, completing the arena migration for boxed values, nullables,
arrays, and dictionaries.

Before, each dict was Rc::into_raw(Rc::new(FeltDict { ... })) with its element buffer on the system heap (alloc/realloc/dealloc) and dup/drop
wired through runtime bindings + per-value drop overrides materialized via Felt252DictOverrides + symbol lookup. Now:

  • cairo_native__dict_new arena-allocates the FeltDict struct and registers it in a thread-local DICT_REGISTRY.
  • cairo_native__dict_get grows the elements buffer via EXECUTION_ARENA.alloc_layout + copy_nonoverlapping instead of realloc.
  • Dict dup is the default (returns the same pointer twice) — safe because dict snapshots in Cairo cannot read inner values. Dict drop is a noop.
  • On InvocationGuard::drop, the registry is drained and each FeltDict's HashMap is drop_in_place'd (the HashMap is the only system-heap
    allocation that survives in the FeltDict). The arena is then reset, freeing the FeltDict struct and elements buffer in one shot.

This removes:

  • src/metadata/felt252_dict.rs (Felt252DictOverrides).
  • The cairo_native__dict_drop / cairo_native__dict_dup runtime bindings.
  • The custom Drop for FeltDict.
  • The find_dict_drop_override closure threaded through every AbiArgument::to_bytes impl and through Value::to_ptr.

Net diff: -894 / +262.

Introduces Breaking Changes?

Yes.

  • AotNativeExecutor::new and JitNativeExecutor::new no longer take a Felt252DictOverrides argument.
  • AbiArgument::to_bytes no longer takes the find_dict_drop_override closure.
  • Value::to_ptr no longer takes the find_dict_drop_override closure.
  • FeltDict no longer has a drop_fn field, no longer impls Drop, and cairo_native__dict_new no longer takes a drop callback.
  • cairo_native__dict_drop and cairo_native__dict_dup symbols are removed.

This change is Reviewable

@TomerStarkware
TomerStarkware requested a review from orizi May 18, 2026 13:40

@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 14 files and all commit messages, and made 1 comment.
Reviewable status: 14 of 16 files reviewed, 1 unresolved discussion (waiting on TomerStarkware).


src/executor.rs line 360 at r1 (raw file):

    blake_call_count: u64,
    execution_arena: Bump,
    dict_registry: Vec<*mut FeltDict>,

probably not really needed.

add todo

Base automatically changed from tomer/sha_and_circuit_arena to main May 18, 2026 14:21
@TomerStarkware
TomerStarkware force-pushed the tomer/arena_dict branch 2 times, most recently from 995e422 to 655aa5d Compare May 18, 2026 21:15

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

@TomerStarkware made 1 comment.
Reviewable status: 14 of 20 files reviewed, 1 unresolved discussion (waiting on orizi).


src/executor.rs line 360 at r1 (raw file):

Previously, orizi wrote…

probably not really needed.

add todo

Done.

@github-actions

github-actions Bot commented May 18, 2026

Copy link
Copy Markdown

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 11.251 ± 0.036 11.196 11.304 6.09 ± 0.08
cairo-native (embedded AOT) 1.848 ± 0.023 1.815 1.875 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 1.888 ± 0.018 1.862 1.922 1.02 ± 0.02

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 555.0 ± 10.4 543.6 577.7 1.00
cairo-native (embedded AOT) 1682.2 ± 35.3 1626.4 1745.4 3.03 ± 0.09
cairo-native (embedded JIT using LLVM's ORC Engine) 1731.2 ± 10.8 1720.2 1756.7 3.12 ± 0.06

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.890 ± 0.104 4.802 5.102 2.27 ± 0.05
cairo-native (embedded AOT) 2.153 ± 0.014 2.127 2.177 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.198 ± 0.020 2.179 2.237 1.02 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.831 ± 0.073 4.756 4.949 2.91 ± 0.06
cairo-native (embedded AOT) 1.660 ± 0.022 1.630 1.689 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 1.705 ± 0.025 1.676 1.760 1.03 ± 0.02

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 591.3 ± 8.4 579.3 607.9 1.00
cairo-native (embedded AOT) 1692.0 ± 17.5 1666.7 1712.5 2.86 ± 0.05
cairo-native (embedded JIT using LLVM's ORC Engine) 1784.7 ± 21.6 1765.8 1837.7 3.02 ± 0.06

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 500.8 ± 4.1 495.8 509.2 1.00
cairo-native (embedded AOT) 1835.6 ± 14.5 1798.1 1849.7 3.67 ± 0.04
cairo-native (embedded JIT using LLVM's ORC Engine) 1999.3 ± 16.2 1977.8 2034.4 3.99 ± 0.05

@github-actions

github-actions Bot commented May 18, 2026

Copy link
Copy Markdown

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 1.895 ± 0.009 1.884 1.913 1.04 ± 0.01
base dict_insert.cairo (AOT) 1.817 ± 0.022 1.780 1.841 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 1.843 ± 0.030 1.801 1.906 1.03 ± 0.02
head dict_insert.cairo (AOT) 1.796 ± 0.022 1.766 1.828 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 1.768 ± 0.021 1.740 1.807 1.05 ± 0.02
base dict_snapshot.cairo (AOT) 1.677 ± 0.021 1.648 1.710 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 1.696 ± 0.025 1.669 1.740 1.06 ± 0.02
head dict_snapshot.cairo (AOT) 1.604 ± 0.015 1.578 1.625 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 2.168 ± 0.024 2.134 2.198 1.03 ± 0.01
base factorial_2M.cairo (AOT) 2.112 ± 0.010 2.095 2.128 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 2.014 ± 0.028 1.962 2.055 1.01 ± 0.02
head factorial_2M.cairo (AOT) 1.988 ± 0.034 1.937 2.051 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 1.714 ± 0.021 1.688 1.743 1.03 ± 0.02
base fib_2M.cairo (AOT) 1.672 ± 0.015 1.649 1.692 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 1.656 ± 0.018 1.629 1.685 1.03 ± 0.02
head fib_2M.cairo (AOT) 1.610 ± 0.016 1.589 1.636 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 1.814 ± 0.017 1.780 1.833 1.06 ± 0.02
base linear_search.cairo (AOT) 1.704 ± 0.023 1.671 1.743 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 1.738 ± 0.033 1.690 1.790 1.04 ± 0.03
head linear_search.cairo (AOT) 1.669 ± 0.032 1.629 1.722 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 2.003 ± 0.026 1.960 2.055 1.06 ± 0.02
base logistic_map.cairo (AOT) 1.890 ± 0.021 1.868 1.925 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 1.972 ± 0.027 1.937 2.027 1.10 ± 0.02
head logistic_map.cairo (AOT) 1.796 ± 0.027 1.736 1.832 1.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 all commit messages and made 1 comment.
Reviewable status: 12 of 20 files reviewed, 2 unresolved discussions (waiting on TomerStarkware).


-- commits line 4 at r2:
rebase

@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 8 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on TomerStarkware).


src/executor.rs line 360 at r1 (raw file):

Previously, TomerStarkware wrote…

Done.

add the why

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

:lgtm:

@orizi reviewed 1 file and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@TomerStarkware
TomerStarkware added this pull request to the merge queue May 19, 2026
Merged via the queue into main with commit 37b8c40 May 19, 2026
26 checks passed
@TomerStarkware
TomerStarkware deleted the tomer/arena_dict branch May 19, 2026 10:43
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