Repository: microsoft/garnet
File: libs/server/Resp/Parser/RespCommand.cs (C#)

Code before:
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private RespCommand ArrayParseCommand(ref int count, ref bool success)
        {
            RespCommand cmd = RespCommand.INVALID;
            ReadOnlySpan<byte> specificErrorMessage = default;
            endReadHead = readHead;
            var ptr = recvBufferPtr + readHead;

            // See if input command is all upper-case. If not, convert and try fast parse pass again.
            if (MakeUpperCase(ptr))
            {
                cmd = FastParseCommand(out count);
                if (cmd != RespCommand.NONE)
                {
                    return cmd;
                }
            }

            // Ensure we are attempting to read a RESP array header
            if (recvBufferPtr[readHead] != '*')
            {
                // We might have received an inline command package. Skip until the end of the line in the input package.
                success = AttemptSkipLine();
                return RespCommand.INVALID;
            }

            // Read the array length
            if (!RespReadUtils.ReadUnsignedArrayLength(out count, ref ptr, recvBufferPtr + bytesRead))
            {
                success = false;
                return RespCommand.INVALID;
            }

            // Move readHead to start of command payload
            readHead = (int)(ptr - recvBufferPtr);

            // Try parsing the most important variable-length commands
            cmd = FastParseArrayCommand(ref count, ref specificErrorMessage);

            if (cmd == RespCommand.NONE)
            {
                cmd = SlowParseCommand(ref count, ref specificErrorMessage, out success);
            }

            // Parsing for command name was successful, but the command is unknown
            if (success && cmd == RespCommand.INVALID)
            {
                if (!specificErrorMessage.IsEmpty)
                {

Review comment (suggestion):
Adding this above line 1887 should make it optimal:

```
  // Reset waitForAofBlocking if there is no pending unsent data on the network
  if (dcurr == networkSender.GetResponseObjectHead()) waitForAofBlocking = false;
```

Code after:

            if (storeWrapper.appendOnlyFile != null && storeWrapper.serverOptions.WaitForCommit)
                HandleAofCommitMode(cmd);

            return cmd;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private void HandleAofCommitMode(RespCommand cmd)
        {
            // Reset waitForAofBlocking if there is no pending unsent data on the network
            if (dcurr == networkSender.GetResponseObjectHead())
                waitForAofBlocking = false;

            // If we are in NetworkSkip's state we do not need to be changing the AOF blocking flag
            // since we do not interact with AOF in that path.
            if (txnManager.state != TxnState.None && txnManager.state == TxnState.Running)
            {
                /* 
                    keeping the expensive call inside the conditional only adds ~4 MSIL instructions in hotpath
                    W.r.t AOF  Blocking
                    If a previous command marked AOF for blocking we should not change AOF blocking flag.
                    If no previous command marked AOF for blocking, then we only change AOF flag to block
                    if the current command is AOF dependent.
                */
                waitForAofBlocking = waitForAofBlocking || !cmd.IsAofIndependent();
            }
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private RespCommand ArrayParseCommand(ref int count, ref bool success)
        {
            RespCommand cmd = RespCommand.INVALID;
            ReadOnlySpan<byte> specificErrorMessage = default;
            endReadHead = readHead;
            var ptr = recvBufferPtr + readHead;

            // See if input command is all upper-case. If not, convert and try fast parse pass again.
            if (MakeUpperCase(ptr))
            {
                cmd = FastParseCommand(out count);
                if (cmd != RespCommand.NONE)
                {
                    return cmd;
                }
            }

            // Ensure we are attempting to read a RESP array header
            if (recvBufferPtr[readHead] != '*')
            {
                // We might have received an inline command package. Skip until the end of the line in the input package.