Optimize parse_in_bracket to avoid unnecessary String allocations

Open Beginner friendly
#9,493 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
performance

Research direction

Start in parquet-variant/src/utils.rs at parse_in_bracket and inspect how VariantPathElement uses Cow. Compare bracket expressions with and without escape sequences, then verify that unescaped content is borrowed, escaped content still parses correctly, and the existing parquet-variant tests remain passing.

Written by the indexing model from the issue text.

Description

enhancement

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

I've noticed that parse_in_bracket in parquet-variant/src/utils.rs always allocates a String when parsing bracket expressions like [field] or [0], even when no escaping is needed:

fn parse_in_bracket(s: &str, i: usize) -> Result<(VariantPathElement<'_>, usize), ArrowError> {
    let start = i + 1;
    let mut unescaped = String::new();  // <-- Always allocates!
    // ...
}

Describe the solution you'd like

I'm thinking of optimizing this by:

  1. Check if the content contains \ before allocating
  2. Since VariantPathElement already supports Cow<'a, str>, we could borrow the slice directly when no escaping is present
  3. Only allocate when we actually encounter escape sequences
Dominant language
Rust
Stars
3.6k
Forks
1.3k
Avg merge
3d 1h
Merged PRs (30d)
147

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/arrow-rs

All issues in apache/arrow-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.