Page MenuHomeFeedback Tracker

Optimization: CarScript:GetCarBattery is very expensive and one of the longest running functions.
New, NormalPublic

Description

The following vanilla code is called every frame for every vehicle on the server and is very expensive to perform. This could be cached onInit and whenever the battery is attached/removed and increase performance significantly.

	ItemBase GetBattery()
	{
		if (IsVitalCarBattery()) 
		{
			return ItemBase.Cast(FindAttachmentBySlotName("CarBattery"));
		}
		else if (IsVitalTruckBattery())
		{
			return ItemBase.Cast(FindAttachmentBySlotName("TruckBattery"));
		}
		
		return null;
	}

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 7
Category
General
Steps To Reproduce

Add cars to a server with the profiler enabled and dump result after a period of about 30 minutes. GetBattery() will be one of the longest running functions.

Event Timeline

antihax created this task.Oct 22 2023, 5:29 PM