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

C#: Allow passing variable number of args to command. #1208

Merged
merged 7 commits into from
Apr 7, 2024

Conversation

nihohit
Copy link
Contributor

@nihohit nihohit commented Apr 1, 2024

This will allow us to expand the C# API to support all commands. This is in preparation of supporting additional commands.
The core change is that Message and the FFI functions aren't written around 2 raw pointers, but they now take an array of raw pointers, which is pinned by the client until operations complete.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@nihohit nihohit requested a review from a team as a code owner April 1, 2024 14:27
@nihohit
Copy link
Contributor Author

nihohit commented Apr 1, 2024

This PR causes a slight performance degradation - below 10%, but I didn't conduct enough benchmarks in order to be precise.
IMO this is a reasonable cost for the capability, and it could probably improved down the line.

@shachlanAmazon
Copy link
Contributor

@Yury-Fridlyand @Sa1Gur

Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

Few things I found so far. Will re-review more thorough later.
Can you add profiling to the client code while benchmarking it? It is worth understanding where those 10% are lost. I have some ideas on optimizationm, but I'd like to see profiling first.

impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
fn from(value: ::protobuf::EnumOrUnknown<ProtobufRequestType>) -> Self {
match value.enum_value_or(ProtobufRequestType::InvalidRequest) {
ProtobufRequestType::InvalidRequest => RequestType::InvalidRequest,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is is possible to use a macro?

Copy link
Contributor

Choose a reason for hiding this comment

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

dunno, you're welcome to try :)


public async Task<string?> SetAsync(string key, string value)
{
var args = this.arrayPool.Rent(2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please avoid this. references to avoid linter warnings in future

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm keeping with the current style. You're welcome to change the style & add a linter to enforce it.

Copy link
Contributor

Choose a reason for hiding this comment

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

As a side note, my pr for enforcing rules #1136 (in particular this one) still waiting for approval. So it might be beneficial to merge it first

glide-core/src/request_type.rs Show resolved Hide resolved
Comment on lines +224 to +228
RequestType::Select => Some(cmd("SELECT")),
RequestType::ConfigGet => Some(get_two_word_command("CONFIG", "GET")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to use a macro (2 macros) here?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe. Your suggestion is unclear, and I'm not taking an open-ended task now.

Comment on lines +29 to +30
GCHandle pinnedArray = GCHandle.Alloc(args, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't stackalloc be faster?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good readings though: one two

Copy link
Contributor

Choose a reason for hiding this comment

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

dunno, you're welcome to profile :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Yury-Fridlyand can you open an issue to check if later on when we'll continue C# develop?

@shachlanAmazon
Copy link
Contributor

Can you add profiling to the client code while benchmarking it?

Hi, I'm going on vacation and will spend a minimal amount of time getting this PR merged. I won't have time for open-ended "maybe do " comments - if you see concrete problems, please point them out. Anything else can be done by someone else, later.

@Yury-Fridlyand Yury-Fridlyand added the C# C# wrapper label Apr 1, 2024
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

I created a task to analyze the performance and research how it can be improved

@barshaul barshaul merged commit ee9ef59 into valkey-io:main Apr 7, 2024
43 of 45 checks passed
shohamazon pushed a commit to adanWattad/glide-for-redis that referenced this pull request Apr 9, 2024
* Expose request type enum which is independent from Protobuf.

* Simplify C# tests by moving shared logic to function.

* C#: Allow passing variable number of args to command.
cyip10 pushed a commit to Bit-Quill/valkey-glide that referenced this pull request Jun 24, 2024
* Expose request type enum which is independent from Protobuf.

* Simplify C# tests by moving shared logic to function.

* C#: Allow passing variable number of args to command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# C# wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants