Skip to content

Tree-Shakeable Serialization #3231

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 4 commits into from
Jun 19, 2020
Merged

Tree-Shakeable Serialization #3231

merged 4 commits into from
Jun 19, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jun 17, 2020

This PR replaces the class methods in JSONSerializer with free standing functions, which allows for a lot of tree shaking (see binary size report).

This PR is split in three parts:

  • fad9e64 is mostly a mechanical Refactor in IntelliJ
  • 005abb3 is a manual change that uses an options interface in lieu of the empty serializer class.
  • 2e9c758 is a small cleanup.
  • 9c4663a is an auto-generated update to the dependency file in the Lite SDK.

This PR is a bit easier to review by appending "?w=1" to the URL.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 17, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (ee421d2) Head (3acd1fd) Diff
    browser 252 kB 250 kB -1.81 kB (-0.7%)
    esm2017 195 kB 195 kB -216 B (-0.1%)
    main 495 kB 493 kB -1.93 kB (-0.4%)
    module 249 kB 248 kB -1.81 kB (-0.7%)
    react-native 195 kB 195 kB -196 B (-0.1%)
  • @firebase/firestore/lite

    Type Base (ee421d2) Head (3acd1fd) Diff
    main 151 kB 140 kB -11.0 kB (-7.3%)
  • @firebase/firestore/memory

    Type Base (ee421d2) Head (3acd1fd) Diff
    browser 192 kB 187 kB -4.94 kB (-2.6%)
    esm2017 149 kB 146 kB -3.31 kB (-2.2%)
    main 371 kB 363 kB -8.29 kB (-2.2%)
    module 190 kB 185 kB -4.94 kB (-2.6%)
    react-native 149 kB 146 kB -3.29 kB (-2.2%)
  • @firebase/testing

    Type Base (ee421d2) Head (3acd1fd) Diff
    main 6.67 kB 6.34 kB -331 B (-5.0%)
  • firebase

    Type Base (ee421d2) Head (3acd1fd) Diff
    firebase-firestore.js 290 kB 287 kB -2.27 kB (-0.8%)
    firebase-firestore.memory.js 231 kB 226 kB -5.28 kB (-2.3%)
    firebase.js 822 kB 819 kB -2.27 kB (-0.3%)

Test Logs

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.

Haven't really reviewed this PR, but a high-level comment.

@@ -93,10 +93,14 @@ export class Firestore implements firestore.FirebaseFirestore {
this._datastorePromise = PlatformSupport.getPlatform()
.loadConnection(databaseInfo)
.then(connection => {
const serializer = PlatformSupport.getPlatform().newSerializer(
const serializationOptions = PlatformSupport.getPlatform().newSerializationOptions(
Copy link
Contributor

Choose a reason for hiding this comment

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

In tree-shakeable style, the structure containing the data we pass through that used to be a class is now just a dumb struct, but it still has the same identity. All that's changed is that it's a dumb struct with accompanying functions instead of a class with member functions.

For parity with the other platforms I think it still makes sense to call that thing a Serializer.

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 parity argument makes sense. I updated the PR accordingly.

Copy link
Contributor

@wu-hui wu-hui left a comment

Choose a reason for hiding this comment

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

There is one place where serializer is not used but in the parameters. Otherwise LGTM.

* Returns a number (or null) from a google.protobuf.Int32Value proto.
*/
function fromInt32Proto(
serializer: JsonProtoSerializer,
Copy link
Contributor

Choose a reason for hiding this comment

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

serializer is not needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed (also in a couple other places)

@wu-hui wu-hui assigned schmidt-sebastian and unassigned wu-hui Jun 19, 2020
@schmidt-sebastian schmidt-sebastian merged commit 338dbfa into master Jun 19, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/serializer branch July 9, 2020 17:44
@firebase firebase locked and limited conversation to collaborators Jul 20, 2020
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.

4 participants