Performances (fps) loss when removing UE_LOG(SomeVariable)

I’m currently creating a plugin. Everything is fine during my debugging, but when I start removing UE_LOG() that lies around, suddenly I get a huge performance hit, about 1/5 of the original performances.

I started by searching if something was broken but everything still works fine and without any bugs of any kind. So I put back some UE_LOG() to see from where the bug is originating. And the performances came back to normal… So I incrementally removed every UE_LOG() to see what’s happening.

I found out that there are 2 places where performances disappear when the UE_LOG() are removed. But if one of them is removed but not the other, the performances are hurt by some amount,. When it is the other one that is removed, the performances are hurt by another amount. And if both are removed, the performances are even lower with another amount which doesn’t seem to be the addition of both loss…

To make things even weirder, the UE_LOG() are displaying a variable which is a simple bool used as return value of a function. This is the same variable in both cases and this variable is only used once (outside the UE_LOG()) for a conditional.

The code is inside a FRunnableThread as a FRunnable and looks like that:

while (state == ECommandReceiverState::Running)
	{
		ReadChannelResult_UL = IPC_Read(ResultData);
		
		if (ReadChannelResult_UL != IPC_NOERROR)
		{
			if (!ProblematicVariable)
			{
				ProblematicVariable = mpGPUResourcesSharingModule_O->Trigger(0);
				UE_LOG(LogCommandReceiver, Warning, TEXT("%d"), ProblematicVariable);	//DO NOT REMOVE, Perfomances penalty (fps/5)
			}
			continue;
		}

		switch (ResultData->Id_UL)
		{
			case COMMONINPUT_ID_PARAMETER_RENDER:
				if (ModuleIsLoaded)
				{
					ProblematicVariable = mpGPUResourcesSharingModule_O->Trigger(0);
					UE_LOG(LogCommandReceiver, Warning, TEXT("%d"), ProblematicVariable);	//DO NOT REMOVE, Perfomances penalty (fps/5)
				}
				break;
			case COMMONINPUT_ID_PARAMETER_SETCAM:
				ResultData[1] = *ResultData;
				break;				
			case COMMONINPUT_ID_PARAMETER_SETROT:
				ResultData[2] = *ResultData;
				break;
			default:
				UE_LOG(LogCommandReceiver, Error, TEXT("Unknown command id: %lu"), ResultData->Id_UL);
				break;
		}

	}

I tried to search for optimization problems but couldn’t find anything. I tried used Sleep(0) to trigger event if any (via the scheduler).

As you can see, there is no obvious reason for that to happen.

If you have any clue about a possible reason and/or fix for this issue, please share it.