Skip to content

⚡ perf: replace expect(&format!(...)) with unwrap_or_else to avoid unnecessary allocations#353

Merged
filmil merged 1 commit intomainfrom
perf-optimize-expect-format-12913409335323361221
Apr 28, 2026
Merged

⚡ perf: replace expect(&format!(...)) with unwrap_or_else to avoid unnecessary allocations#353
filmil merged 1 commit intomainfrom
perf-optimize-expect-format-12913409335323361221

Conversation

@filmil
Copy link
Copy Markdown
Member

@filmil filmil commented Apr 28, 2026

💡 What: Replaced the use of .expect(&format!(...)) with .unwrap_or_else(|e| panic!(...)) in the test suites of rust_icu_ecma402/src/numberformat.rs and rust_icu_ecma402/src/datetimeformat.rs.
🎯 Why: The format! macro allocates a new String every time it's called. When used inside expect(), this allocation happens on every execution, including the success path. Using unwrap_or_else ensures that formatting and allocation only occur if a panic is actually triggered.
📊 Measured Improvement: A meaningful performance improvement could not be demonstrated via benchmarks due to environment limitations (missing libicu-dev and inability to download crates offline). However, this is a standard Rust performance optimization that eliminates unnecessary allocations in hot paths or frequently run tests.

This commit was created by an automated coding assistant, with human supervision.


PR created automatically by Jules for task 12913409335323361221 started by @filmil

Replaced `.expect(&format!(...))` with `.unwrap_or_else(|e| panic!(...))`
in `rust_icu_ecma402/src/numberformat.rs` and `rust_icu_ecma402/src/datetimeformat.rs`.
This avoids unnecessary string allocations on the success path.

This commit was created by an automated coding assistant, with human supervision.

Co-authored-by: filmil <246576+filmil@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@filmil filmil merged commit 279b577 into main Apr 28, 2026
14 checks passed
@filmil filmil deleted the perf-optimize-expect-format-12913409335323361221 branch April 28, 2026 08:14
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