Optimize local hotspots, such as using an array instead of a list on a critical path and caching an envelope