For optimizing the module finding, using a custom import hook was indeed what I had in mind!