-
Notifications
You must be signed in to change notification settings - Fork 517
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
[Compatibility] Added INCRBYFLOAT command #699
[Compatibility] Added INCRBYFLOAT command #699
Conversation
Why not use Utf8Parser.TryParse? The open PR #631 also uses it. |
Or, |
For other direction, check this: |
might be best to just convert the double to the ROS with a sufficiently large buffer, to know how many bytes it uses. hopefully the conversion will not need to be repeated. |
@badrishc I have added the benchmark results with Utf8Formatter. In my benchmark, it is the slowest option. I've shared below my benchmark method for using Utf8Formatter, please let me know if I made any mistake in my benchmark. Note: We can't use exponential notation. [Benchmark]
public byte NumOfCharInDoubleWithUtf8Formatter()
{
Span<byte> buffer = stackalloc byte[327]; // 309 (max digits) + 1 (dot) + 17 (precision)
Utf8Formatter.TryFormat(Value, buffer, out var bytesWritten, new StandardFormat('f', 17));
buffer = buffer.Slice(0, bytesWritten).TrimEnd((byte)'0').TrimEnd((byte)'.');
return buffer[0];
} |
NumOfCharInDoubleWithMathAbsRound seems better as high-perf scenarios might involve smaller doubles. cc @PaulusParssinen for thoughts on this. |
Nicely done PR, approved! |
Please resolve the conflicts and we can move forward. |
@Vijay-Nirmal - there seems to be a perf regression with this PR, for Increment: BDN paramters: main:
PR:
AnalysisIt seems this is related to the |
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.
Can you please add a slot verification test in ClusterSlotVeficationTests?
@badrishc Interesting, For @badrishc Is there any thumb rule on when to add RespParseStress? @vazois That a new things to me, I will add it, also same question Is there any thumb rule on when to add ClusterSlotVeficationTests? I will do everything this weekend |
I tried making
Ideally for all "fast" commands we add so that we can track future perf regressions. However it is understandably extra work, so it is mostly on a case-by-case basis for now. |
I made some updates and additions in this PR (#709) for slot verification. |
@vazois Added ClusterSlotVeficationTests. Can you review and approve the PR? |
We will merge this PR now. Vijay - if you can add the ClusterSlotVerificationTest in a separate PR, that would be great. |
@badrishc Already added ClusterSlotVerificationTest in this PR itself |
@@ -387,7 +387,7 @@ Note that this list is subject to change as we continue to expand our API comman | |||
| | GETSET | ➖ | | | |||
| | [INCR](raw-string.md#incr) | ➕ | | | |||
| | [INCRBY](raw-string.md#incrby) | ➕ | | | |||
| | INCRBYFLOAT | ➖ | | | |||
| | [INCRBYFLOAT](raw-string.md#incrbyfloat) | ➖ | | |
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.
@Vijay-Nirmal Presumably "-" should have been changed to "+".
Currently INCRBYFLOAT
may look like not implemented with the minus sign
https://microsoft.github.io/garnet/docs/commands/api-compatibility
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.
This PR should fix this, if accepted #757
Adding INCRBYFLOAT command to garnet
Question:
Do you guys have any optimal way to
double
to ASCIIbyte
?Below is a benchmark with 2 approaches.
DoubleToSpanWithMathAbsRound => Same code as the PR
DoubleToSpanWithDiyFp => Similar code as
string.Format("{0:0.####}")
. Below are the links to the code I used from .dotnet runtime repoNumber.DiyFp.cs
Number.Grisu3.cs - TryRunCounted
DoubleToSpanWithStringFormat => Using
doubleValue.ToString("0.###############")
and using buffer copy to move the value to input spanDoubleToSpanWithUtf8Formatter => Using Utf8Formatter
DoubleToSpanWithTryFormat => Using
doubleValue.TryFormat(buffer, out var bytesWritten, "0.#################")
Even though the dotnet runtime approach does better in most cases in the benchmark, I have not done it as part of this PR because of 2 reasons, 1) it has lots of code and 2) for smaller numbers it always performs worse. If you guys like dotnet's approach, I can change it quickly.
Let me know if you guys have any other ideas, I can implement and compare the performance.