Skip to content

⚡ Bolt: Optimize Value::integer() and Value::float() conversions#47

Merged
ashyanSpada merged 1 commit into
masterfrom
bolt-optimize-value-integer-float-1351915934699169371
Mar 26, 2026
Merged

⚡ Bolt: Optimize Value::integer() and Value::float() conversions#47
ashyanSpada merged 1 commit into
masterfrom
bolt-optimize-value-integer-float-1351915934699169371

Conversation

@ashyanSpada
Copy link
Copy Markdown
Owner

💡 What: Replaced inefficient string conversion/parsing (to_string().parse()) inside Value::integer() and Value::float() with direct conversion traits (to_i64 and to_f64). Added check for scale() == 0 to integer to strictly preserve former failure characteristics.
🎯 Why: To avoid inefficient heap allocations caused by intermediate stringifications, which improves performance and reduces memory usage in the expression engine.
📊 Impact: Reduces memory usage from string allocation and lowers CPU execution time significantly for integer and float value access.
🔬 Measurement: Verify by running cargo test and observing logic tests pass, and via cargo bench to benchmark conversions.


PR created automatically by Jules for task 1351915934699169371 started by @ashyanSpada

Replaced inefficient `to_string().parse()` stringification in `Value::integer` and `Value::float` conversions with direct conversions using `to_i64` and `to_f64` from `rust_decimal::prelude::ToPrimitive`. Kept the edge case check for `scale() == 0` for `integer()` to strictly maintain parser behavior parity. Added corresponding test cases.

Co-authored-by: ashyanSpada <22587148+ashyanSpada@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.

Copilot AI review requested due to automatic review settings March 25, 2026 21:41
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly optimizes the conversion of Value::Number types to i64 and f64. By transitioning from inefficient string-based parsing to direct numeric conversion traits, the changes reduce memory allocations and CPU overhead, thereby enhancing the overall performance of the expression engine. Additionally, a strict scale check was implemented for integer conversions to maintain consistent behavior.

Highlights

  • Performance Optimization for Value Conversions: Replaced inefficient string-based to_string().parse() with direct to_i64() and to_f64() trait methods for Value::integer() and Value::float() to improve efficiency and reduce heap allocations.
  • Strict Integer Conversion Behavior: Introduced a scale() == 0 check in Value::integer() to ensure strict adherence to integer representation, mirroring the failure characteristics of the previous string parsing method for non-integer decimals.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes Decimal to i64 and f64 conversions in the Value type by switching from string-based parsing to direct rust_decimal::prelude::ToPrimitive trait methods (to_i64, to_f64). For integer conversions, a strict check val.scale() == 0 is introduced to maintain behavioral parity with string parsing, rejecting decimal values with non-zero scales. New unit tests validate these changes. The review suggests refactoring the integer method's match statement to use a match guard for better readability and conciseness.

Comment thread src/value.rs
Comment on lines 98 to 107
match self {
Self::Number(val) => val
.to_string()
.parse()
.map_or(Err(Error::InvalidInteger), |num| Ok(num)),
Self::Number(val) => {
if val.scale() == 0 {
val.to_i64().ok_or(Error::InvalidInteger)
} else {
Err(Error::InvalidInteger)
}
}
_ => Err(Error::InvalidInteger),
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and conciseness, you can use a match guard. This simplifies the logic by incorporating the val.scale() == 0 check directly into the match arm, removing the nested if/else block.

        match self {
            Self::Number(val) if val.scale() == 0 => val.to_i64().ok_or(Error::InvalidInteger),
            _ => Err(Error::InvalidInteger),
        }

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.55%. Comparing base (75d247f) to head (34b4736).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
+ Coverage   89.17%   89.55%   +0.38%     
==========================================
  Files          11       11              
  Lines        1062     1063       +1     
==========================================
+ Hits          947      952       +5     
+ Misses        115      111       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes numeric extraction from Value::Number(Decimal) by replacing string-based conversions with direct rust_decimal primitive conversions, reducing allocations and improving runtime performance in the expression engine.

Changes:

  • Replaced to_string().parse() with to_i64() / to_f64() in Value::integer() and Value::float().
  • Preserved prior integer() failure behavior by rejecting decimals with scale() != 0.
  • Added unit tests covering the updated conversion behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/value.rs Uses ToPrimitive conversions for integer/float accessors and adds unit tests for conversion semantics.
.jules/bolt.md Documents the conversion optimization and the scale()==0 parity requirement as a bolt learning/action.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ashyanSpada ashyanSpada merged commit 9a4a6cc into master Mar 26, 2026
26 checks passed
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.

2 participants