In terms of how you fix this, you probably need to make some new admin_setting_... classes. For example, to output hte JavaScript, you need to subclass something, and output the JS from the _html method.
When you need to do something expensive to load the choices for a select menu, there is a way to do lazy-loading, so the choices are only set up on pages where the select will acutally be shown. There are two examples here: https://github.com/moodle/moodle/blob/master/mod/quiz/settingslib.php#L160