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; }