-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix construction with same type performing convert #36
Conversation
725c932
to
4634bc8
Compare
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
==========================================
+ Coverage 98.81% 98.82% +<.01%
==========================================
Files 1 1
Lines 169 170 +1
==========================================
+ Hits 167 168 +1
Misses 2 2
Continue to review full report at Codecov.
|
Can you post some performance benchmarks? |
4634bc8
to
33c664d
Compare
…is the same Before this change: ``` julia> x = f = FixedDecimal{Int128,2}(3.25) >> FixedDecimal{Int128,2}(3.25) julia> @Btime x = FixedDecimal{Int128, 2}($f) 7.272 μs (159 allocations: 2.73 KiB) >> FixedDecimal{Int128,2}(3.25) ``` After this change: ``` julia> x = f = FixedDecimal{Int128,2}(3.25) >> FixedDecimal{Int128,2}(3.25) julia> @Btime x = FixedDecimal{Int128, 2}($f) 1.508 ns (0 allocations: 0 bytes) >> FixedDecimal{Int128,2}(3.25) ```
33c664d
to
1ad557e
Compare
Yes, definitely! Sorry, i had this tiny "benchmark" in the commit text, but didn't post it in the PR:
But I'll also post up a better benchmark in a second. |
Okay, so here's the benchmarks that originally led me here. Here's the benchmark in a gist: And the results in a google spreadsheet: For some reason, even just element-wise copying an array of I was trying to find the source of that allocation, which led me to this change. It doesn't actually address the fact that Int128s are allocating when copied, when the other sizes don't, but it does eliminate unnecessary work, by preventing a Separately, though, it would be really nice to identify the source of the allocations for Int128. |
Reposting results:
|
(Note that after this PR, the benchmarks don't change. This is more like a minor optimization I discovered while researching the weird allocations. Maybe I'll open another issue for the benchmarks then separately!) :) |
(Opened #37 to discuss the weird allocation and other questions) |
Before this PR, constructing a new FD with the same type called
convert
. That happened due to this line, sinceFD<: Real
:FixedPointDecimals.jl/src/FixedPointDecimals.jl
Line 113 in cc6aed3
This PR adds a "copy constructor" to avoid that. I'm not really sure what the idiomatic name for it would be in julia, "copy constructor" of course references the name of the same concept in C++. :)
Perhaps a separate issue is that for some reason
convert
is super expensive whenT=Int128
, which is how I stumbled across this problem. But either way, i think this PR could make sense.