Skip to content

perf: use zero-copy slice for binary/hex/octal number parsing#5488

Merged
max-sixty merged 1 commit intoPRQL:mainfrom
max-sixty:parser-allocations
Oct 12, 2025
Merged

perf: use zero-copy slice for binary/hex/octal number parsing#5488
max-sixty merged 1 commit intoPRQL:mainfrom
max-sixty:parser-allocations

Conversation

@max-sixty
Copy link
Copy Markdown
Member

@max-sixty max-sixty commented Oct 10, 2025

Summary

Use .to_slice() instead of .collect::<String>() when parsing binary, hexadecimal, and octal number literals. This eliminates one allocation per literal by passing a string slice directly to i64::from_str_radix() instead of allocating an intermediate String.

The change also simplifies the code by removing an unnecessary allocation step.

Changes

// Before
.collect::<String>()
.map(move |digits| {
    i64::from_str_radix(&digits, base)

// After  
.to_slice()
.map(move |digits: &str| {
    i64::from_str_radix(digits, base)

Test plan

  • All existing tests pass (task prqlc:test)
  • 569 tests passing, no regressions
  • Clippy clean

🤖 Generated with Claude Code

Use `.to_slice()` instead of `.collect::<String>()` when parsing
binary, hexadecimal, and octal number literals. This eliminates one
allocation per literal by passing a string slice directly to
`i64::from_str_radix()` instead of allocating an intermediate String.

The change also simplifies the code by removing an unnecessary
allocation step.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty changed the title perf: reduce allocations in lexer number parsing perf: use zero-copy slice for binary/hex/octal number parsing Oct 12, 2025
@max-sixty max-sixty enabled auto-merge (squash) October 12, 2025 20:29
@max-sixty max-sixty merged commit df4bbd4 into PRQL:main Oct 12, 2025
39 checks passed
@max-sixty max-sixty deleted the parser-allocations branch October 12, 2025 20:31
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.

1 participant