Before searching for bottlenecks check the ms times for the different engine parts.
If you see entity rendering at 20ms and scripts at 0.5ms, then simply forget optimizing the script - even if things can be improved there. It will give you next to no improvement. Instead you should check where the 20 ms rendering tme for entities is coming from.