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

Use struct for DiyFp #450

Merged
merged 1 commit into from Dec 21, 2017
Merged

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Dec 19, 2017

By converting DiyFp to struct we can lower memory traffic by about 30% with small performance gain. I'm using the array test again here.

I have also internalized the Dtoa bits so that no poor soul takes dependency on them, I believe they are not something that library should offer as part of the API.

/cc @sebastienros @ayende

Before

Method N ReuseEngine Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Jint 20 False 4.169 s 2.139 s 0.1209 s 784750.0000 40500.0000 17500.0000 3.18 GB
Jint 20 True 4.090 s 1.327 s 0.0750 s 786750.0000 40250.0000 18500.0000 3.17 GB

After

Method N ReuseEngine Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Jint 20 False 4.006 s 0.9027 s 0.0510 s 537000.0000 36750.0000 17000.0000 2.19 GB
Jint 20 True 3.987 s 0.1880 s 0.0106 s 539500.0000 40250.0000 18500.0000 2.19 GB

@@ -52,17 +51,16 @@ internal CachedPower(ulong significand, short binaryExponent, short decimalExpon
}


internal static int GetCachedPower(int e, int alpha, int gamma, DiyFp cMk)
internal static (short, DiyFp) GetCachedPower(int e, int alpha, int gamma)
Copy link
Owner

Choose a reason for hiding this comment

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

Would there be less allocations if you used two out values instead of a Tuple ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ValueTuple is a struct so it wont' allocate memory. I did quick check on the out alternative and benchmarkdotnet showed both ways to allocate 0B and ValueTuple version being slightly faster (can't explain that).

@sebastienros sebastienros merged commit 0e6b4dc into sebastienros:dev Dec 21, 2017
@lahma lahma mentioned this pull request Dec 22, 2017
@lahma lahma deleted the perf/DiyFp-as-struct branch February 11, 2018 20:39
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.

None yet

2 participants