Repository: microsoft/onnxruntime
File: onnxruntime/core/mlas/lib/convolve.cpp (C++)

Code before:
        WorkBlock.Bias = Bias;
        WorkBlock.WorkingBuffer = nullptr;
        WorkBlock.Output = Output;
        WorkBlock.TargetThreadCount = TargetThreadCount;

        MlasExecuteThreaded(MlasConvGemmDirectThreaded, &WorkBlock, TargetThreadCount, ThreadPool);

        return;
    }

#if defined(MLAS_TARGET_WASM_SCALAR)

    if (Algorithm == MlasConvAlgorithmDepthwise) {
        // Fill the Working Buffer with Zero for use by the depthwise kernel.
        // The length for the zeros are input image wide + 2 currently.
        std::fill_n(WorkingBuffer, Parameters->InputShape[1] + 2, 0.0f);
    }

#endif

    if (Algorithm == MlasConvAlgorithmExpandThenGemmSegmented && ((BatchCount > 1) || (GroupCount > 1))) {
        const size_t BatchGroupCount = BatchCount * GroupCount;

        ptrdiff_t TargetThreadCount = MlasGetMaximumThreadCount(ThreadPool);

        if (size_t(TargetThreadCount) >= BatchGroupCount) {
            TargetThreadCount = static_cast<ptrdiff_t>(BatchGroupCount);
        }

        MLAS_CONV_WORK_BLOCK WorkBlock;

        WorkBlock.Parameters = Parameters;
        WorkBlock.Input = Input;
        WorkBlock.Filter = Filter;
        WorkBlock.Bias = Bias;
        WorkBlock.WorkingBuffer = WorkingBuffer;
        WorkBlock.Output = Output;
        WorkBlock.TargetThreadCount = TargetThreadCount;

        MlasExecuteThreaded(MlasConvExpandThenGemmSegmentedThreaded, &WorkBlock, TargetThreadCount, ThreadPool);

        return;
    }

    //
    // Iterate over each batch and group.
    //
    for (size_t batch = 0; batch < BatchCount; batch++) {

        const float* filter = Filter;
        const float* bias = Bias;

Review comment (performance):
```suggestion
        if (static_cast<size_t>(TargetThreadCount) >= BatchGroupCount) {
```

Code after:
        WorkBlock.Bias = Bias;
        WorkBlock.WorkingBuffer = nullptr;
        WorkBlock.Output = Output;
        WorkBlock.TargetThreadCount = TargetThreadCount;

        MlasExecuteThreaded(MlasConvGemmDirectThreaded, &WorkBlock, TargetThreadCount, ThreadPool);

        return;
    }

#if defined(MLAS_TARGET_WASM_SCALAR)

    if (Algorithm == MlasConvAlgorithmDepthwise) {
        // Fill the Working Buffer with Zero for use by the depthwise kernel.
        // The length for the zeros are input image wide + 2 currently.
        std::fill_n(WorkingBuffer, Parameters->InputShape[1] + 2, 0.0f);
    }

#endif

    if (Algorithm == MlasConvAlgorithmExpandThenGemmSegmented && ((BatchCount > 1) || (GroupCount > 1))) {
        const size_t BatchGroupCount = BatchCount * GroupCount;

        ptrdiff_t TargetThreadCount = MlasGetMaximumThreadCount(ThreadPool);

        if (static_cast<size_t>(TargetThreadCount) >= BatchGroupCount) {
            TargetThreadCount = static_cast<ptrdiff_t>(BatchGroupCount);
        }

        MLAS_CONV_WORK_BLOCK WorkBlock;

        WorkBlock.Parameters = Parameters;
        WorkBlock.Input = Input;
        WorkBlock.Filter = Filter;
        WorkBlock.Bias = Bias;
        WorkBlock.WorkingBuffer = WorkingBuffer;
        WorkBlock.Output = Output;
        WorkBlock.TargetThreadCount = TargetThreadCount;

        MlasExecuteThreaded(MlasConvExpandThenGemmSegmentedThreaded, &WorkBlock, TargetThreadCount, ThreadPool);

        return;
    }

    //
    // Iterate over each batch and group.
    //
    for (size_t batch = 0; batch < BatchCount; batch++) {

        const float* filter = Filter;
        const float* bias = Bias;