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

Performance fix: avoid unnecessary convert on setindex!、copy when type is same. #38

Merged
merged 2 commits into from
Nov 12, 2018

Conversation

NHDaly
Copy link
Member

@NHDaly NHDaly commented Nov 7, 2018

Add convert(::Type{T}, x::T) where {T<:FD} = x

This fixes unnecessary copies on setindex!, etc.

Fixes the allocations issue for identity from this table, by preventing the widening to BigInt:
#37

This is the same situation as this issue:
JuliaLang/julia#17559

@NHDaly NHDaly force-pushed the noop-convert-to-self branch from 1d38bb5 to dd155ab Compare November 7, 2018 23:28
src/FixedPointDecimals.jl Outdated Show resolved Hide resolved
This fixes unnecessary copies on `setindex!`, etc.
@NHDaly NHDaly force-pushed the noop-convert-to-self branch from dd155ab to 9276173 Compare November 8, 2018 01:45
@coveralls
Copy link

Coverage Status

Coverage increased (+0.007%) to 98.83% when pulling 9276173 on NHDaly:noop-convert-to-self into d87debb on JuliaMath:master.

@coveralls
Copy link

coveralls commented Nov 8, 2018

Coverage Status

Coverage remained the same at 98.824% when pulling 54d2d5a on NHDaly:noop-convert-to-self into d87debb on JuliaMath:master.

@codecov-io
Copy link

codecov-io commented Nov 8, 2018

Codecov Report

Merging #38 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
+ Coverage   98.82%   98.83%   +<.01%     
==========================================
  Files           1        1              
  Lines         170      171       +1     
==========================================
+ Hits          168      169       +1     
  Misses          2        2
Impacted Files Coverage Δ
src/FixedPointDecimals.jl 98.83% <100%> (ø) ⬆️

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 d87debb...9276173. Read the comment docs.

The "copy constructor" is no longer necessary now that a no-op
`convert` is added, since by default construction falls back to convert.

To verify, after this change, the performance is still correct:
```
julia> f = FixedPointDecimals.FixedDecimal{Int128,2}(3.25)
FixedDecimal{Int128,2}(3.25)

julia> @Btime x = FixedPointDecimals.FixedDecimal{Int128, 2}($f)
  0.036 ns (0 allocations: 0 bytes)
FixedDecimal{Int128,2}(3.25)
```

And `@code_native` shows this to be a simple reinterpret.
@NHDaly
Copy link
Member Author

NHDaly commented Nov 8, 2018

(I've also removed the copy constructor that I added in #36, since this is the more general and correct fix.)

And verified that the performance is unchanged:

julia> f = FixedPointDecimals.FixedDecimal{Int128,2}(3.25)
FixedDecimal{Int128,2}(3.25)

julia> @btime x = FixedPointDecimals.FixedDecimal{Int128, 2}($f)
  0.036 ns (0 allocations: 0 bytes)
FixedDecimal{Int128,2}(3.25)

Copy link
Contributor

@omus omus left a comment

Choose a reason for hiding this comment

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

LGTM

@omus omus merged commit 1768c58 into JuliaMath:master Nov 12, 2018
@NHDaly NHDaly deleted the noop-convert-to-self branch November 13, 2018 00:35
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.

4 participants