-
Notifications
You must be signed in to change notification settings - Fork 927
Remove asserts #2814
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 asserts #2814
Conversation
Binary Size ReportAffected SDKs
Test Logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes me deeply uncomfortable because we have no idea how the SDK will behave with assertions removed. I suspect we'd get close to the same savings by removing the text of the assertion without removing the actual check. That would at least avoid the possibility of proceeding in an undefined state.
If you really want to wholesale remove assertions, I think we need to audit just what kind of data corruption could be possible without them and probably turn those into errors we just handle directly. For example, if watch gives us corrupt responses, we currently assert about that, but we should instead just drop the message/reset the stream. Absent work like that, this seems pretty irresponsible.
This is a branch with all messages removed: #2820 (for now this is just done via refactoring, rather than code transformation. We likely want to stick with code transformation to make testing and development easier). What stands out though is that almost all of our asserts are for internal state (like calling start() before using instance methods, type checking and in general verifying that our own generated data is sane). There are very few asserts that center around the backend protocol (but there are some, e.g. we verify the number of returned documents from a BatchGetDocuments and the number of returned mutation responses). The size savings for the uncompressed memory-only build are reduced by roughly 3% if we only strip out the messages. The IndexedDB build is 2% smaller with the asserts completely removed. Note that Google strips asserts in its TypeScript build if "recommended settings" are used: With out current pipeline, we could also treat the memory-only build different from the IndexedDB-build and only strip asserts from the memory-only build, which would reduce the risk of corruption. We could also start differentiating between "debugAsserts" and "runtimeAsserts" and keep the few asserts that take into account external input. Or we could decided that 2.2% is not worth this effort and just strip out the messages.... |
I favor differentiating debug asserts from runtime asserts, though maybe we could call those Secondarily I wonder if we should replace hard asserts with proper error handling. That is: if we get an invalid value from watch, drop the whole message and proceed after logging rather than crashing? I think we could proceed with this PR with only the first part and leave the latter suggestion for later. |
Updated the PR to remove the newly added "debugAsserts". With this, the savings are now 5-7% since we are not (yet) special-casing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR removes all asserts from our minified builds. This results in 7-10% savings before GZIP (see below).
The non-minified integration tests continue to run against the build with asserts. The Node build is not minified/mangled and continues to contains the asserts (referred to as "main" build below).
This is based on prior work in master...mikelehen:mikelehen/size-remove-asserts