Skip to content

Make MemoryLru tree-shakeable #2767

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 2 commits into from
Mar 20, 2020
Merged

Make MemoryLru tree-shakeable #2767

merged 2 commits into from
Mar 20, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Mar 19, 2020

Our hard-coded dependency means that tree-shaking doesn't remove the unused LRU code for memory persistence. This PR removes the dependency and should also completely remove the estimated byte size accounting in the field value rewrite.

Before:
317762 firebase-firestore.js
274464 firebase-firestore.memory.js

After:
315861 firebase-firestore.js
270591 firebase-firestore.memory.js

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.

I know very little about tree-shaking, can you explain a bit why removing static factory methods helps?

LGTM still.

@wu-hui wu-hui assigned schmidt-sebastian and unassigned wu-hui Mar 20, 2020
@schmidt-sebastian
Copy link
Contributor Author

My five second summary of tree shaking: Our build pipeline drops unused imports and top-level exports. So if you have:

class A {}
class B {}
const b = B();

A won't be in the final bundle. If instead, you have:

class A {}
class B {  
 function unused() {
  return new A();
 }
}
const b = B();

RollUp doesn't know whether you are actually using B.unused() and hence A (since there is no guarantee for strong typings). In this snippet, A and B are included in the final bundle.

@schmidt-sebastian schmidt-sebastian merged commit 9200feb into master Mar 20, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/dontlru branch March 26, 2020 03:05
@firebase firebase locked and limited conversation to collaborators Apr 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.

2 participants