Skip to content

bench(arrow-cast): Add decimal formatting benchmark - #10997

Merged
Jefffrey merged 1 commit into
apache:mainfrom
neilconway:neilc/bench-format-decimal
Sep 6, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
neilconway:neilc/bench-format-decimal

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

Add format_decimal.rs, which formats arrays of 8192 random values through ArrayFormatter like format_temporal.rs does, for Decimal32, Decimal64, Decimal128 and Decimal256 at representative precisions and scales, with digit counts that cover values below the scale, values that fit an i128 and the widest Decimal256 values.

There was previously no benchmark that covered formatting decimals.

What changes are included in this PR?

See above.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

Add format_decimal.rs, which formats arrays of 8192 random values
through ArrayFormatter like format_temporal.rs does, for Decimal32,
Decimal64, Decimal128 and Decimal256 at representative precisions and
scales, with digit counts that cover values below the scale, values that
fit an i128 and the widest Decimal256 values. There was previously no
benchmark that covered formatting decimals.
@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Sep 6, 2026
@Jefffrey
Jefffrey merged commit 738e69c into apache:main Sep 6, 2026
42 checks passed
@Jefffrey

Jefffrey commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

thanks @neilconway & @Rich-T-kid

Jefffrey added a commit that referenced this pull request Sep 6, 2026
# Which issue does this PR close?

- N/A

# Rationale for this change

Display for i256 converted the value to a num-bigint value and formatted
that, which allocates the BigInt's digit vector and runs a generic
arbitrary-precision conversion.

By formatting the value ourselves, we can do better because we don't
need to support arbitrary precision, and we can also avoid the heap
allocation and type conversion overhead.

format_decimal benchmark (#10997), Apple M4 Max:

    case                              before     after   change
    decimal256 (76, 10) 38 digits    1730.13    958.33   -44.6%
    decimal256 (76, 10) 76 digits    2088.60   1760.90   -15.7%

The win is bigger for small Decimal256 values because we can do those
entirely in i128; in principle num-bigint could implement a similar
optimization for small values, but it currently does not. Decimal256
values larger than i128 are split into three chunks and formatted as
i128; this is still faster than going through num-bigint.

In practice, this improves the performance of writing out decimal values
as CSV and JSON, as well as pretty-printing them.

# What changes are included in this PR?

See above.

# Are these changes tested?

Yes; new test added, existing tests pass.

# Are there any user-facing changes?

No; decimal format is unchanged.

# AI usage

Developed with Claude Code Fable 5.1; reviewed with Codex Astra 6. I
reviewed, revised, and understand the resulting code.

Co-authored-by: Jeffrey Vo <[email protected]>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 18, 2026
# Which issue does this PR close?

- N/A

# Rationale for this change

Add `format_decimal.rs`, which formats arrays of 8192 random values
through ArrayFormatter like `format_temporal.rs` does, for Decimal32,
Decimal64, Decimal128 and Decimal256 at representative precisions and
scales, with digit counts that cover values below the scale, values that
fit an i128 and the widest Decimal256 values.

There was previously no benchmark that covered formatting decimals.

# What changes are included in this PR?

See above.

# Are these changes tested?

Yes.

# Are there any user-facing changes?

No.
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 18, 2026
# Which issue does this PR close?

- N/A

# Rationale for this change

Display for i256 converted the value to a num-bigint value and formatted
that, which allocates the BigInt's digit vector and runs a generic
arbitrary-precision conversion.

By formatting the value ourselves, we can do better because we don't
need to support arbitrary precision, and we can also avoid the heap
allocation and type conversion overhead.

format_decimal benchmark (apache#10997), Apple M4 Max:

    case                              before     after   change
    decimal256 (76, 10) 38 digits    1730.13    958.33   -44.6%
    decimal256 (76, 10) 76 digits    2088.60   1760.90   -15.7%

The win is bigger for small Decimal256 values because we can do those
entirely in i128; in principle num-bigint could implement a similar
optimization for small values, but it currently does not. Decimal256
values larger than i128 are split into three chunks and formatted as
i128; this is still faster than going through num-bigint.

In practice, this improves the performance of writing out decimal values
as CSV and JSON, as well as pretty-printing them.

# What changes are included in this PR?

See above.

# Are these changes tested?

Yes; new test added, existing tests pass.

# Are there any user-facing changes?

No; decimal format is unchanged.

# AI usage

Developed with Claude Code Fable 5.1; reviewed with Codex Astra 6. I
reviewed, revised, and understand the resulting code.

Co-authored-by: Jeffrey Vo <[email protected]>
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 21, 2026
# Which issue does this PR close?

- N/A

# Rationale for this change

Add `format_decimal.rs`, which formats arrays of 8192 random values
through ArrayFormatter like `format_temporal.rs` does, for Decimal32,
Decimal64, Decimal128 and Decimal256 at representative precisions and
scales, with digit counts that cover values below the scale, values that
fit an i128 and the widest Decimal256 values.

There was previously no benchmark that covered formatting decimals.

# What changes are included in this PR?

See above.

# Are these changes tested?

Yes.

# Are there any user-facing changes?

No.
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Sep 21, 2026
# Which issue does this PR close?

- N/A

# Rationale for this change

Display for i256 converted the value to a num-bigint value and formatted
that, which allocates the BigInt's digit vector and runs a generic
arbitrary-precision conversion.

By formatting the value ourselves, we can do better because we don't
need to support arbitrary precision, and we can also avoid the heap
allocation and type conversion overhead.

format_decimal benchmark (apache#10997), Apple M4 Max:

    case                              before     after   change
    decimal256 (76, 10) 38 digits    1730.13    958.33   -44.6%
    decimal256 (76, 10) 76 digits    2088.60   1760.90   -15.7%

The win is bigger for small Decimal256 values because we can do those
entirely in i128; in principle num-bigint could implement a similar
optimization for small values, but it currently does not. Decimal256
values larger than i128 are split into three chunks and formatted as
i128; this is still faster than going through num-bigint.

In practice, this improves the performance of writing out decimal values
as CSV and JSON, as well as pretty-printing them.

# What changes are included in this PR?

See above.

# Are these changes tested?

Yes; new test added, existing tests pass.

# Are there any user-facing changes?

No; decimal format is unchanged.

# AI usage

Developed with Claude Code Fable 5.1; reviewed with Codex Astra 6. I
reviewed, revised, and understand the resulting code.

Co-authored-by: Jeffrey Vo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-cast development-process Internal changes; PRs with this label are excluded from changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants