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

Adding wrongType bool to GarnetObjectStoreOutput #923

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TalZaccai
Copy link
Contributor

@TalZaccai TalZaccai commented Jan 18, 2025

This change is to avoid checking for GarnetObjectStoreOutput.spanByteAndMemory.Length == 0 in order to determine if object operation was attempted on a mismatched type (and by that to allow object operations to return an empty output and avoid unnecessary allocations)

Benchmarks for module operations after the change:
Note: # of allocated bytes decreased for ObjRmw, ObjRead & JsonSet.

Method Params Mean Error StdDev Median Gen0 Allocated
ModuleNoOpRawStringReadCommand None 55.37 us 1.969 us 5.422 us 53.53 us - -
ModuleNoOpRawStringRmwCommand None 63.87 us 1.275 us 3.031 us 63.01 us - -
ModuleNoOpObjRmwCommand None 89.03 us 1.994 us 5.786 us 87.00 us - 3200 B
ModuleNoOpObjReadCommand None 73.87 us 1.469 us 2.794 us 73.74 us - 3200 B
ModuleNoOpProc None 45.70 us 0.889 us 1.092 us 45.64 us - -
ModuleNoOpTxn None 38.86 us 0.760 us 1.519 us 38.79 us - -
ModuleJsonGetCommand None 154.14 us 2.852 us 4.765 us 153.92 us - 72800 B
ModuleJsonSetCommand None 269.16 us 5.345 us 13.312 us 268.49 us 0.4883 223200 B

@badrishc
Copy link
Contributor

Why isn't allocated at zero after this change? Need to check what else gets allocated on critical path. There doesn't logically seem to be anything else needed.

@@ -47,7 +47,11 @@ public bool InitialUpdater(ref byte[] key, ref ObjectInput input, ref IGarnetObj
if ((byte)type < CustomCommandManager.CustomTypeIdStartOffset)
{
value = GarnetObject.Create(type);
value.Operate(ref input, ref output.spanByteAndMemory, out _, out _);
value.Operate(ref input, ref output.spanByteAndMemory, out _, out _, out var wrongType);
Copy link
Contributor

Choose a reason for hiding this comment

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

Operate should take in ref GOSO instead of adding another out param. cc @TedHartMS

/// <returns></returns>
bool Operate(ref ObjectInput input, ref SpanByteAndMemory output, out long sizeChange, out bool removeKey);
bool Operate(ref ObjectInput input, ref SpanByteAndMemory output, out long sizeChange, out bool removeKey, out bool wrongType);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please clean this up if possible, remove size change and remove key. Put into enum perhaps?

/// <summary>
/// True if an operation was attempted on the wrong type of object
/// </summary>
public bool wrongType;
Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed making this an enum, please check that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I missed that comment :) Can do!

"expected_ModuleNoOpRawStringReadCommand_AOF": 0,
"expected_ModuleNoOpRawStringRmwCommand_AOF": 0,
"expected_ModuleNoOpObjRmwCommand_AOF": 8800,
"expected_ModuleNoOpObjReadCommand_AOF": 5600,
"expected_ModuleNoOpObjRmwCommand_AOF": 3200,
Copy link
Contributor

Choose a reason for hiding this comment

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

Scope of this PR may be a bit narrow, IMHO. Better if one PR handles all the technical debt related to custom ops perf, since each individual item is rather straightforward, technically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this one is self-contained and unrelated to the changes which have to do with the CustomCommandManager, makes it easier to review and pinpoint to a certain commit if something needs to be debugged / reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants