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

Remove usages of assert in all code that ends up bundled in the browser #4144

Merged
merged 26 commits into from
Oct 29, 2020

Conversation

christiango
Copy link
Member

Resolves #4070

With this change we remove all client side usages of assert to dramatically reduce bundle sizes. Also adds a custom webpack plugin to the bundle size tests to cause PRs that add new instances of assert will fail to build.

This reduces the container from 240KB (62.5KB compressed) to 180KB (45.5KB compressed)

@christiango
Copy link
Member Author

This PR can't be merged until #4140 and #4139 are merged

@@ -0,0 +1,64 @@
/*!
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this file need to be here? I.e. should it be separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

It keeps it from regressing, I can move it to another PR if that helps review this one.

@@ -346,7 +346,7 @@ export class PermutationVector extends Client {
}

default:
assert.fail();
throw new Error();
Copy link
Contributor

Choose a reason for hiding this comment

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

Having at least some text here would be nice :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestions for what it should say?

@@ -327,7 +327,9 @@ export class ConsensusOrderedCollection<T = any>
}
if (local) {
assert(
localOpMetadata, `localOpMetadata is missing from the local client's ${op.opName} operation`);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change cast below to include undefined and move this assert after it, testing resolve for not being undefined.
That said, maybe even better - just remove assert, it does not add much value - we will crash one way or another if things go wrong

@@ -255,7 +254,10 @@ export class ConsensusRegisterCollection<T>
message.sequenceNumber,
local);
if (local) {
assert(localOpMetadata, "localOpMetadata is missing from the client's write operation");
assert(
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, I'd just remove it

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.

Consider moving away from assert for code that runs in the browser
3 participants