-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
1d38bb5
to
dd155ab
Compare
This fixes unnecessary copies on `setindex!`, etc.
dd155ab
to
9276173
Compare
Codecov Report
@@ Coverage Diff @@
## master #38 +/- ##
==========================================
+ Coverage 98.82% 98.83% +<.01%
==========================================
Files 1 1
Lines 170 171 +1
==========================================
+ Hits 168 169 +1
Misses 2 2
Continue to review full report at Codecov.
|
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.
(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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 toBigInt
:#37
This is the same situation as this issue:
JuliaLang/julia#17559