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

Command argument parsing improvements #255

Merged
merged 45 commits into from
Apr 20, 2024

Conversation

PaulusParssinen
Copy link
Contributor

@PaulusParssinen PaulusParssinen commented Apr 7, 2024

Culture invariant parsing

  • Avoid re-encoding ASCII and allocating temporary strings, instead feed bytes into directly to Utf8Parser.TryParse
    • In 02cca16, this change indirectly fixes the issue where cultures with decimal seperator being comma instead of dot caused some of Geo RESP tests fail.
    • UPDATE: Fixed all remaining floating point formatting too by passing InvariantCulture to Parse and ToString.
  • Avoid some CurrentCulture lookups by using ToUpperInvariant instead of ToUpper
  • Use StringComparison.OrdinalIgnoreCase where we otherwise allocated uppercase string for string comparison. This equality comparison is also much faster as it doesn't care about cultures.
    • And use StringComparison.Ordinal where applicable for perf (it gets unrolled for constant inputs à la SequenceEquals).StringComparison.OrdinalIgnoreCase also gets unrolled for constants in .NET 8 but has to deal with some bit flipping for the case insensitivity.

Enums

  • Use Enum.TryParse instead of catching exceptions for Enum.Parse, much more cheaper.
  • Use generic enum parsing overloads, allows JIT to see the type and optimize it better.

Misc.

  • Removed unused methods from RespReadUtils
  • Added internal ArgSlice.FromPinnedSpan
    • Necessary evil that will allow further simplifications in future contributions.
    • In this PR, it allow simplifying the HashObject's IncrementIntegerOrFloat logic.

* We can avoid allocating intermediary arrays and extra fixing now
…piate

* Avoid string allocation & avoid current thread culture lookup for equals

* Switched some ToUpper to ToUpperInvariant too
* Avoid CurrentCulture lookup
* Also switch over to generic overloads, allows JIT to see what type is used
* We completely spanify these later, the calls got ugly
* Thanks github web editor
@lmaas lmaas added the parser label Apr 8, 2024
@lmaas lmaas self-assigned this Apr 8, 2024
@badrishc badrishc requested a review from vazois April 8, 2024 20:31
libs/cluster/Session/ClusterCommands.cs Outdated Show resolved Hide resolved
libs/cluster/Session/FailoverCommand.cs Outdated Show resolved Hide resolved
@PaulusParssinen PaulusParssinen marked this pull request as draft April 9, 2024 19:59
@PaulusParssinen PaulusParssinen changed the title Minor command argument parsing improvements Command argument parsing improvements Apr 10, 2024
@badrishc badrishc requested a review from lmaas April 16, 2024 00:19
@badrishc
Copy link
Contributor

badrishc commented Apr 16, 2024

@vazois @lmaas - any additional comments on this PR? Is it ready for merge?

libs/server/Metrics/Info/InfoCommand.cs Outdated Show resolved Hide resolved
libs/server/ACL/ACLParser.cs Outdated Show resolved Hide resolved
libs/server/Resp/Bitmap/BitmapCommands.cs Outdated Show resolved Hide resolved
libs/server/Resp/Bitmap/BitmapCommands.cs Outdated Show resolved Hide resolved
* StringComparison.Ordinal gets unrolled by JIT
Copy link
Contributor

@lmaas lmaas left a comment

Choose a reason for hiding this comment

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

Excellent work! There are a lot of good changes in this PR. Thank you for working on this.

I have added a few comments with suggestions for improvement. Let’s address those points before merging. Once we’ve resolved the questions, I’ll be happy to perform another review.

libs/server/ACL/ACLParser.cs Outdated Show resolved Hide resolved
libs/server/ACL/ACLParser.cs Outdated Show resolved Hide resolved
libs/server/Objects/Hash/HashObjectImpl.cs Outdated Show resolved Hide resolved
libs/server/Objects/ObjectUtils.cs Outdated Show resolved Hide resolved
libs/server/ACL/ACLParser.cs Outdated Show resolved Hide resolved
libs/cluster/Server/ClusterConfig.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@lmaas lmaas left a comment

Choose a reason for hiding this comment

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

Great job on the code! Your thorough work is much appreciated. I believe we’re ready to merge this PR. Thank you for your valuable contribution! 🙌

@lmaas lmaas merged commit 03611e1 into microsoft:main Apr 20, 2024
21 checks passed
@PaulusParssinen PaulusParssinen deleted the avoid-ascii-re-encoding branch April 20, 2024 19:51
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants