apache / apache/arrow-rs

Optimize parse_in_bracket to avoid unnecessary String allocations

Open Beginner friendly
#9,493 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
3.6k
Forks
1.3k
Avg merge
2d 14h
Merged PRs (30d)
167

Description

**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:

```rust
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

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.