Repository: microsoft/garnet
File: libs/server/Objects/ItemBroker/CollectionItemBroker.cs (C#)

Code before:
                                    newObj = true;
                                }
                                else if (dstObj is ListObject tmpDstList)
                                {
                                    dstList = tmpDstList;
                                }
                                else return false;

                                isSuccessful = TryMoveNextListItem(listObj, dstList, (OperationDirection)cmdArgs[1].ReadOnlySpan[0],
                                    (OperationDirection)cmdArgs[2].ReadOnlySpan[0], out nextItem);
                                result = new CollectionItemResult(key, nextItem);

                                if (isSuccessful && newObj)
                                {
                                    isSuccessful = storageSession.SET(arrDstKey, dstList, ref objectLockableContext) ==
                                                   GarnetStatus.OK;
                                }

                                return isSuccessful;
                            case RespCommand.BLMPOP:
                                var popDirection = (OperationDirection)cmdArgs[0].ReadOnlySpan[0];
                                var _ = ParseUtils.TryReadInt(ref cmdArgs[1], out var popCount); // Int should has be validated in the Network layer (Server Session) itself
                                popCount = popCount < 1 ? 1 : popCount; // Default when count is not provided
                                popCount = Math.Min(popCount, listObj.LnkList.Count);

                                var items = new byte[popCount][];
                                for (var i = 0; i < popCount; i++)
                                {
                                    if (!TryGetNextListItem(listObj, popDirection == OperationDirection.Left ? RespCommand.BLPOP : RespCommand.BRPOP, out items[i]))
                                    {
                                        return false;
                                    }
                                }

                                result = new CollectionItemResult(key, items);
                                return true;
                            default:
                                return false;
                        }
                    case SortedSetObject setObj:
                        currCount = setObj.Dictionary.Count;
                        if (objectType != GarnetObjectType.SortedSet) return false;

                        var hasValue = TryGetNextSetObject(setObj, command, out var sortedSetNextItem);
                        result = new CollectionItemResult(key, sortedSetNextItem);
                        return hasValue;
                    default:
                        return false;
                }
            }
            finally

Review comment (suggestion):
If you can, please add `if (currCount == 0) return false` at the beginning of the switch case, no reason to incur any cost if the list is empty.

Code after:
                                if (dstObj == null)
                                {
                                    dstList = new ListObject();
                                    newObj = true;
                                }
                                else if (dstObj is ListObject tmpDstList)
                                {
                                    dstList = tmpDstList;
                                }
                                else return false;

                                isSuccessful = TryMoveNextListItem(listObj, dstList, (OperationDirection)cmdArgs[1].ReadOnlySpan[0],
                                    (OperationDirection)cmdArgs[2].ReadOnlySpan[0], out nextItem);
                                result = new CollectionItemResult(key, nextItem);

                                if (isSuccessful && newObj)
                                {
                                    isSuccessful = storageSession.SET(arrDstKey, dstList, ref objectLockableContext) ==
                                                   GarnetStatus.OK;
                                }

                                return isSuccessful;
                            case RespCommand.BLMPOP:
                                var popDirection = (OperationDirection)cmdArgs[0].ReadOnlySpan[0];
                                var popCount = *(int*)(cmdArgs[1].ptr);
                                popCount = Math.Min(popCount, listObj.LnkList.Count);

                                var items = new byte[popCount][];
                                for (var i = 0; i < popCount; i++)
                                {
                                    var _ = TryGetNextListItem(listObj, popDirection == OperationDirection.Left ? RespCommand.BLPOP : RespCommand.BRPOP, out items[i]); // Return can be ignored because it is guaranteed to return true
                                }

                                result = new CollectionItemResult(key, items);
                                return true;
                            default:
                                return false;
                        }
                    case SortedSetObject setObj:
                        currCount = setObj.Dictionary.Count;
                        if (objectType != GarnetObjectType.SortedSet) return false;

                        var hasValue = TryGetNextSetObject(setObj, command, out var sortedSetNextItem);
                        result = new CollectionItemResult(key, sortedSetNextItem);
                        return hasValue;
                    default:
                        return false;
                }
            }
            finally
            {