Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize component part construction #155

Merged
merged 3 commits into from
Mar 25, 2022
Merged

Conversation

ancapdev
Copy link
Contributor

Component part construction performs some redundant conversions on constants.

The conversions are more costly than they look, as the decimal to integer path range checks against type ranges on the integer types, which in turn performs conversions of these to the decimal type. For Dec128/UInt128 this is particularly bad as the integer to decimal conversion falls back to conversion via strings.

Fixed by precomputing integer constants.

Simple example benchmark in the form of

@btime T($(Ref(123))[], $(Ref(-8))[])
T before after
Dec32 10.701 ns (0 allocations: 0 bytes) 4.200 ns (0 allocations: 0 bytes)
Dec64 11.912 ns (0 allocations: 0 bytes) 3.810 ns (0 allocations: 0 bytes)
Dec128 394.069 ns (6 allocations: 288 bytes) 6.510 ns (0 allocations: 0 bytes)

@stevengj
Copy link
Member

stevengj commented Mar 25, 2022

Would be good to add tests of the form:

@test DecFP._int_maxintfloat(Dec32) === UInt32(maxintfloat(Dec32))
@test DecFP._int_maxintfloat(Dec64) === UInt64(maxintfloat(Dec64))
@test DecFP._int_maxintfloat(Dec128) === UInt128(maxintfloat(Dec128))

@ancapdev
Copy link
Contributor Author

Would be good to add tests of the form:

@test DecFP._int_maxintfloat(Dec32) === UInt32(maxintfloat(Dec32))
@test DecFP._int_maxintfloat(Dec64) === UInt64(maxintfloat(Dec64))
@test DecFP._int_maxintfloat(Dec128) === UInt128(maxintfloat(Dec128))

Makes sense, done

src/DecFP.jl Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 25, 2022

Codecov Report

Merging #155 (4e27f04) into master (e3c133d) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #155      +/-   ##
==========================================
+ Coverage   92.32%   92.38%   +0.05%     
==========================================
  Files           1        1              
  Lines         417      420       +3     
==========================================
+ Hits          385      388       +3     
  Misses         32       32              
Impacted Files Coverage Δ
src/DecFP.jl 92.38% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3c133d...4e27f04. Read the comment docs.

@stevengj
Copy link
Member

LGTM. The 32-bit failures are not a regression (see #91).

@stevengj stevengj merged commit a677c85 into JuliaMath:master Mar 25, 2022
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