Skip to content

perf: avoid redundant String clones in doc parser#9307

Closed
Bashmunta wants to merge 1 commit intostarkware-libs:mainfrom
Bashmunta:perf/doc-parser-avoid-string-clones
Closed

perf: avoid redundant String clones in doc parser#9307
Bashmunta wants to merge 1 commit intostarkware-libs:mainfrom
Bashmunta:perf/doc-parser-avoid-string-clones

Conversation

@Bashmunta
Copy link
Contributor

Summary

This change removes unnecessary String allocations when parsing documentation links. The link resolver now accepts &str instead of owning a String, and the CommentLinkToken Display implementation no longer clones its path field.


Type of change

Please check one:

  • Performance improvement

Why is this change needed?

As a result, we reuse a single String instance per link and pass references into the resolver, keeping the behavior unchanged while reducing allocation overhead in the documentation parser.


@reviewable-StarkWare
Copy link

This change is Reviewable

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


crates/cairo-lang-doc/src/parser.rs line 219 at r1 (raw file):

                                _ => {
                                    let path = dest_url.clone().into_string();
                                    let resolved_item = self.resolve_linked_item(item_id, &path);

this still alocates the string in the SmolStrId::from - so not really any better.

@Bashmunta Bashmunta closed this Dec 29, 2025
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.

3 participants