lib: improve module loading performance
This commit improves module loading performance by at least ~17-23% in the module-loader benchmarks.
This improvement is on top of the module loading performance boost brought on by #5123. Both PRs combined bring a total of ~54% improvement in module loading.
Some optimization strategies include:
- Try-finally/try-catch isolation
- Replacing regular expressions with manual parsers
- Avoiding unnecessary string and array creation
- Avoiding constant recompilation of anonymous functions and function definitions within functions