Skip to content

perf: divide without allocation when parsing doubles - #7973

Open
g4lb wants to merge 1 commit into
alibaba:mainfrom
g4lb:perf-double-divide
Open

g4lb wants to merge 1 commit into
alibaba:mainfrom
g4lb:perf-double-divide

Conversation

@g4lb

@g4lb g4lb commented Nov 27, 2026

Copy link
Copy Markdown

What this PR does / why we need it?

TypeUtils.doubleValue makes new int[] arrays in MutableBigInteger.divideKnuthLong for each value. A 128/64-bit division gives the same result without allocation when the quotient fits in a long.

Summary of your change

doubleValue calls the new divideKnuthLongFast. floatValue does not change.

Benchmark Before After Change
double[], 50 values 959 ns 645 ns −33%
Bean with 4 double values 540 ns 500 ns −7.5%
Other double forms, float no change

The results are the same on 1M random inputs. I measured on ARM with JDK 21.

中文说明

TypeUtils.doubleValue 每次都在 MutableBigInteger.divideKnuthLong 中分配 int[]。当商可以放入 long 时,128/64 位除法可得到相同结果,且无需分配内存。doubleValue 改为调用新方法 divideKnuthLongFast,floatValue 不变。100 万个随机输入结果相同。仅在 ARM + JDK 21 上测量。

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@CLAassistant

CLAassistant commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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