-
-
Notifications
You must be signed in to change notification settings - Fork 846
FastGuid.NewGuid()
helper
#1414
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
Conversation
Thanks, interesting suggestion; can you please run our benchmarks and post before and after results here? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1414 +/- ##
===========================================
+ Coverage 78.48% 78.54% +0.06%
===========================================
Files 200 201 +1
Lines 5703 5720 +17
Branches 1168 1168
===========================================
+ Hits 4476 4493 +17
Misses 714 714
Partials 513 513 ☔ View full report in Codecov by Sentry. |
Benchmark:
Tested on Windows, dotnet 8. |
Ok, can you compare the existing Autofac benchmarks as well, the ones in our "bench" folder (https://github.com/autofac/Autofac/tree/develop/bench/Autofac.Benchmarks)? Want to understand the overall impact of the change on Autofac, based on how many guids we generate. |
What are specific Benchmarks which depends on I ran the entire set Before & After this change and don't see performance improvement. But the benchmarks mostly test Environment: x64, Linux
After:
|
Interesting that it's coming out worse...have you benchmarked dictionary lookups when Guids from FastGuid are used as a key? I'm wondering (without evidence) if the GetHashCode distribution of the guids are not spread out in the same way as with Guid.NewGuid? |
I have tried to mix bits of
But it does not show visible improvement. |
* FastGuid improved 25% faster implementation of FastGuid with MemoryMarshal * fix usings --------- Co-authored-by: Sergei Pavlov <spavlov@servicetitan.com>
Thanks to @snaumenko-st for further improvement of this PR: 88272de Benchmark results look not worse than before. |
Trying to figure out the state of this so I can get a 0.1.0 release out for #1415. I may just release that one without this, regardless. However, looking at the chain here, it sounds like:
It's not interesting to add an optimization that doesn't do anything, so I'm not sure where that leaves us. If it's something where we can show some really marked improvement like "it used to take 10 seconds to start this app and now it takes half a second" or whatever, I'm all for it. But I'm not super interested in optimizing the "we told Autofac to scan and register every type in the entire app and all assemblies" use case - folks shouldn't be doing that, and the pain may be a forcing factor to tell them they're doing something wrong, especially if we're still supporting |
In our case most of restrations happen at App start, but a few additional happen at every Web Request. |
I think I still need to see some sort of improvement, which means this PR possibly needs to include adding some benchmarks that show the affected path and can show that there's improvement. It'd just be nice to see that it's not, like, "2ns improvement" or something basically meaningless. I saw the benchmark of raw GUID creation, but it'd be good to benchmark it in the context of the whole execution path. |
Added a Before:
After:
|
Let me verify I'm reading this right: After adding the fast GUID optimization, across six registrations you'll save about four microseconds (0.7us per registration) but allocate 1KB more memory to get that. Does that sound right? |
Yes. Second run of this benchmark confirms. |
Hmmm. Maybe @alistairjevans feels differently, but... I... I have to admit, I kind of lean against this given the trade-off between the microseconds vs. allocations doesn't add up. |
Yeah, I have to agree, the extra code complexity doesn't seem worth the tiny time gains, and we also don't understand the dictionary bucket impacts enough to know that any gain would be consistent anyway. |
Was that profiling session captured on windows or Linux? |
Linux Debian x64 .NET8 |
Ah; is that also where you've been running benchmarks? |
Not exactly May be |
Is it possible to run the benchmarks in that environment? Again, it'd just be nice to verify that this is going to fix the issue before it gets accepted. |
I did (isolated Guid benchmark only). The results on Azure are the same as on bare Linux. A agree, it is not enough to be merge into Autofac |
Sounds good. We'll close this one out for now, but if you can show that it will be a marked improvement in some environments maybe we can revive it and target those environments. |
It is well-known that standard
Guid.NewGuid()
is slow.And even slower on Linux dotnet/runtime#13628
If GUIDs are not published outside of process it is enough to use global 64-bit counter as part of GUID generator.