Skip to content

Remove enum overhead #2697

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

Merged
merged 12 commits into from
Mar 4, 2020
Merged

Remove enum overhead #2697

merged 12 commits into from
Mar 4, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Feb 29, 2020

This removes the overhead that Enums introduce in TypeScript by changing our enums to "const enums" which can be inlined: https://www.typescriptlang.org/docs/handbook/enums.html#const-enums

This also reverts some of the changes that were made to the OnlineState enum and uses the same solution.

Size before: 318393 bytes (90882 gzipped)
Size after: 315811 bytes (89863 gzipped - 1.2%)

@schmidt-sebastian
Copy link
Contributor Author

Note that the TypeScript style guides recommends against this, but the reasons do not apply to our codebase.

@schmidt-sebastian
Copy link
Contributor Author

FYI @Feiyang1

@@ -51,7 +51,7 @@ export class EventManager implements SyncEngineListener {
q.canonicalId()
);

private onlineState: OnlineState = 'Unknown';
private onlineState: OnlineState = OnlineState.Unknown;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can now probably move the explicit type here (i.e. restore it back to)

private onlineState = OnlineState.Unknown;

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Note that this was part of a straight revert.

/**
* The Firestore client is in an unknown online state. This means the client
* is either not actively trying to establish a connection or it is currently
* trying to establish a connection, but it has not succeeded or failed yet.
* Higher-level components should not operate in offline mode.
*/
| 'Unknown'
Unknown = 'Unknown',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the strings in here anymore? Can these just be numeric?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The string values are persisted in WebStorage (but it is mostly transient data). I added a comment to explain this.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Mar 4, 2020
@schmidt-sebastian schmidt-sebastian merged commit ac25570 into master Mar 4, 2020
@firebase firebase locked and limited conversation to collaborators Apr 3, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/enums branch April 6, 2020 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants