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

perf(emit): decrease emitted code #169

Merged
merged 4 commits into from
Jan 14, 2020
Merged

Conversation

Pmyl
Copy link
Collaborator

@Pmyl Pmyl commented Jan 13, 2020

This PR decreate emitted code by using minification techniques and by not always using get/set for properties. The emitted code is reduced in average by 35%.

Use case is mocking the entire @types/babel-types module:

Current version
626583 characters

ADD assign properties by always using element access (m["prop"] = 0)
447669 characters

ADD reduced string identifier for factory (create__NAME__mock to @NAME)
434162 characters

ADD element access only when signature is there, otherwise object literal (m = { "prop": 0 })
428726 characters

ADD undefined -> void 0 and don't assign void 0 properties
408600

ADD false -> !1 and true -> !0
404922

I've also found that by reducing Repository/Merge/Extension import variable name and methods name to 1-2 characters we could even drop that number to 35k~ but I think that needs more investigation.

…d by not always using get/set for properties
@@ -4,6 +4,8 @@ import { KeyCounter } from './keyCounter';
export type PossibleDeclaration = ts.InterfaceDeclaration | ts.ClassDeclaration | ts.TypeAliasDeclaration;

export class FactoryUniqueName {
private static AnonymousIdentifierText: string = '*';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put these values with the other one? Do you think it's a good idea to keep all these "reduced" identifier names in one place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Member

@uittorio uittorio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small thing :)

@Pmyl
Copy link
Collaborator Author

Pmyl commented Jan 14, 2020

@uittorio I've also renamed mockProperty.ts to reflect the new purpose

@Pmyl Pmyl merged commit 0253e95 into master Jan 14, 2020
@uittorio uittorio deleted the feature/decrease_emitted_code branch January 14, 2020 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants