Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compiler flag to collapse module IIFEs #4652

Closed
mbebenita opened this issue Sep 4, 2015 · 5 comments
Closed

Add compiler flag to collapse module IIFEs #4652

mbebenita opened this issue Sep 4, 2015 · 5 comments
Labels
Duplicate An existing issue was already created Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@mbebenita
Copy link

If you have multiple classes in the same module namespace but defined in different files (or even just different module blocks) TypeScript's tsc will wrap every one of them into its own nest of IIFEs; one for each level of namespace nesting.

For deep namespace hierarchies this produces large amounts of code that increases code size and hurts parsing / loading performance.

To solve this problem, we use a post processing tool (https://github.com/tschneidereit/typescript-module-merger) to merge subsequent modules that appear in the same namespace. This is not a sound optimization but works well in practice. Such a feature should be part of the TypeScript compiler, perhaps under a compiler flag.

@danquirk
Copy link
Member

danquirk commented Sep 4, 2015

We've certainly had this request many times over the years (back before the GitHub era). We generally do few optimizations (and particularly not type directed ones) and have been very hesitant to ever do one that isn't guaranteed to be safe, even if it's under a special flag. How much is your code size changed using this tool vs not?

@mbebenita
Copy link
Author

We've seen ~3-4% overhead due to module IIFEs in the final build, after running the closure compiler and removing whitespace on fairly large files (1MB+).

@danquirk
Copy link
Member

danquirk commented Sep 4, 2015

Did you run closure with other minifications on or just removing whitespace?

@mbebenita
Copy link
Author

We use a custom build of closure that renames locals but leaves property names alone.

@danquirk danquirk added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Sep 8, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Feb 22, 2016

duplicate of #447

@mhegazy mhegazy closed this as completed Feb 22, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 22, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants