Will "optimizing" this code actually help it?

I’ve got some physics code for my plane engine, here is a simplified demonstration of how the source code looks like:

game["Run Service"].PreSimulation:ConnectParallel(function(dt)
	-- other code before plane physics
	for droneName, droneData in pairs(RunningDrones) do
		-- calculates physics
		
		task.synchronize()
		-- applies physics to drone
	end
end)

Is switching to the method below the correct use for parrarel lua? I’m not new to lua but I am experimenting with parrarel.

local physicResultCache = {}
game["Run Service"].PreSimulation:ConnectParallel(function(dt)
	-- other code before plane physics
	task.synchronize()
	for droneName, droneData in pairs(RunningDrones) do
		local dPhysics = physicResultCache[droneName]
		-- Applies physics to the drone...
	end
	task.desynchronize()
	for droneName, droneData in pairs(RunningDrones) do
		-- Calculates physics
		physicResultCache[droneName] = ...
	end
end)
2 Likes

Bump time bump time bump time bump