Have you run some profiling on this code to determine that it is the cause of the slow page load? ( https://docs.moodle.org/dev/Setting_up_xhprof_on_Moodle
http://tjhunt.blogspot.co.uk/2013/05/performance-testing-moodle.html )
If you have and this is the main bottleneck, then I am surprised, as most of those calls are fairly lightweight (get_fast_modinfo should come straight from the cache in 99% of situations, get_module_types_names is a single DB query, the first time it is called on a page; all the rest of the calls to the modinfo object are working with data already in memory).