[CSHARP-1972] Performance of method ToHexString() Created: 29/Apr/17 Updated: 06/Feb/24 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Performance |
| Affects Version/s: | 2.4.3 |
| Fix Version/s: | 2.4.4 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Viktor Svyatokha | Assignee: | Damien Guard |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | devexp-product, performance | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
From several profiling sessions of my application I've noticed that method ToHexString() is used very often. DotTrace has also marked it as one of hot methods during profiling. I've found a solution which has about 40x speedup in compare with current implementation.
Benchmark code: https://gist.github.com/ahydrax/477fedfe5a44bb49ff862b554694a4f1 |
| Comments |
| Comment by Damien Guard [ 06/Feb/24 ] |
|
Hi Viktor. We're going through some older PRs that were overlooked for various reasons and taking another look. I re-ran the benchmarks on .NET 7 and also included using the new `Convert.ToHex` function available in .NET 5.0 and later. The new Convert.ToHex uses SIMD instructions where appropriate and has very highly optimized code offering further performance gains. I'm going to recommend we switch to that as part of the C# Driver 3.0 work when we drop support for older targets. |
| Comment by Daniel Hegener [ 20/Feb/19 ] |
|
Additional PR https://github.com/mongodb/mongo-csharp-driver/pull/285 |
| Comment by Githook User [ 04/May/17 ] |
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: CSHARP-1972: Optimize BsonUtils.ToHexString and ObjectId.ToString. |
| Comment by Viktor Svyatokha [ 29/Apr/17 ] |
|
http://joxi.ru/gmvgWe9HLwRzV2 detailed profiling info for this method I can't provide full stack trace because of NDA but I'll try to provide as much info as possible |
| Comment by Craig Wilson [ 29/Apr/17 ] |
|
Interesting. Thanks for sending. I'm not surprised that ours is slow. We didn't spend time optimizing it. I am surprised that it's showing up in the hot path, which is why we didn't spend any time optimizing it. Do you know that stacktrace that was ultimately causing it to get hit so often? |