Skip to content

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 24, 2026

Summary

Refactored the serialization and deserialization of OrderedHashMap in the debug info module to use a more efficient approach. Instead of collecting items into a temporary vector, the implementation now directly serializes elements into a sequence. For deserialization, introduced a custom Visitor implementation that properly handles sequence access and constructs the map directly.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • Performance improvement
  • New feature
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The previous implementation of serialization and deserialization for OrderedHashMap was inefficient as it created intermediate collections. This change improves performance by eliminating the need for temporary vectors during serialization and deserialization processes.


What was the behavior or documentation before?

Previously, the code would collect all map entries into a temporary vector during serialization, and similarly deserialize into a vector before converting back to an OrderedHashMap.


What is the behavior or documentation after?

Now the implementation directly serializes map entries into a sequence without the intermediate collection. For deserialization, a custom Visitor implementation properly handles sequence access and constructs the map directly with appropriate size hints when available.


Additional context

This change follows serialization best practices by using the visitor pattern for deserialization and direct sequence serialization, which should be more memory efficient for large maps.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@eytan-starkware reviewed 1 file and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi and @TomerStarkware).


crates/cairo-lang-sierra/src/debug_info.rs line 208 at r1 (raw file):

    serializer: S,
) -> Result<S::Ok, S::Error> {
    let mut seq = serializer.serialize_seq(Some(m.len()))?;

Why not serializer.collect_seq(...)?


crates/cairo-lang-sierra/src/debug_info.rs line 228 at r1 (raw file):

        type Value = OrderedHashMap<Id, SmolStr>;

        fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

Essentially reimplementing indexmap: https://docs.rs/indexmap/latest/src/indexmap/map/serde_seq.rs.html#1-138

@orizi orizi changed the base branch from orizi/01-23-refactor_utils_simplified_serde_implementation_of_map_and_set_wrappers to graphite-base/9525 January 25, 2026 11:51
Copy link
Collaborator Author

@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 made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware).


crates/cairo-lang-sierra/src/debug_info.rs line 208 at r1 (raw file):

Previously, eytan-starkware wrote…

Why not serializer.collect_seq(...)?

Done.


crates/cairo-lang-sierra/src/debug_info.rs line 228 at r1 (raw file):

Previously, eytan-starkware wrote…

Essentially reimplementing indexmap: https://docs.rs/indexmap/latest/src/indexmap/map/serde_seq.rs.html#1-138

cool.
Done.

Copy link
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed all commit messages and made 1 comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @eytan-starkware).

Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware made 1 comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi).


crates/cairo-lang-sierra/src/debug_info.rs line 208 at r1 (raw file):

Previously, orizi wrote…

Done.

not seeing it

@orizi orizi force-pushed the graphite-base/9525 branch from ed9d971 to 19723f9 Compare January 25, 2026 12:23
@orizi orizi force-pushed the orizi/01-23-improve_sierra_debug_info_serde branch from 8573a25 to cb68427 Compare January 25, 2026 12:23
@orizi orizi changed the base branch from graphite-base/9525 to orizi/01-23-refactor_utils_simplified_serde_implementation_of_map_and_set_wrappers January 25, 2026 12:23
Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware reviewed all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @orizi).


crates/cairo-lang-sierra/src/debug_info.rs line 228 at r1 (raw file):

Previously, orizi wrote…

cool.
Done.

No change here as well

Copy link
Collaborator Author

@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 made 2 comments.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @eytan-starkware).


crates/cairo-lang-sierra/src/debug_info.rs line 208 at r1 (raw file):

Previously, eytan-starkware wrote…

not seeing it

got the wrong PR - done now.


crates/cairo-lang-sierra/src/debug_info.rs line 228 at r1 (raw file):

Previously, eytan-starkware wrote…

No change here as well

same - yeah - it is essentially the same thing.

Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware made 1 comment.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @orizi).


crates/cairo-lang-sierra/src/debug_info.rs line 228 at r1 (raw file):

Previously, orizi wrote…

same - yeah - it is essentially the same thing.

And we are already using the indexmap serialization in other places. Why reimplement? We have 3 ordered hash map de/serialize

Copy link
Collaborator Author

@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 made 1 comment.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @eytan-starkware).


crates/cairo-lang-sierra/src/debug_info.rs line 228 at r1 (raw file):

Previously, eytan-starkware wrote…

And we are already using the indexmap serialization in other places. Why reimplement? We have 3 ordered hash map de/serialize

the id conversion is required. (Id::new(k))

Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

SIERRA_UPDATE_NO_CHANGE_TAG=No interface change.
@orizi orizi changed the base branch from orizi/01-23-refactor_utils_simplified_serde_implementation_of_map_and_set_wrappers to graphite-base/9525 January 25, 2026 12:56
@orizi orizi force-pushed the orizi/01-23-improve_sierra_debug_info_serde branch from cb68427 to 5681777 Compare January 25, 2026 12:56
@orizi orizi force-pushed the graphite-base/9525 branch from 19723f9 to 58308ae Compare January 25, 2026 12:56
@orizi orizi changed the base branch from graphite-base/9525 to main January 25, 2026 12:56
@orizi orizi added this pull request to the merge queue Jan 25, 2026
Merged via the queue into main with commit aa81a46 Jan 25, 2026
108 checks passed
@orizi orizi deleted the orizi/01-23-improve_sierra_debug_info_serde branch January 26, 2026 21:15
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.

4 participants