firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.86k stars 894 forks source link

Firestore import - Bundle size is huge #2241

Closed maheshkumar2150 closed 4 years ago

maheshkumar2150 commented 5 years ago

import firebase from '@firebase/app'; import '@firebase/firestore'; // this one is very very huge.

I am using only firestore in my app. How to reduce the bundle size of firestore?

GriffinJohnston commented 4 years ago

@schmidt-sebastian Any chance of an update on progress?

schmidt-sebastian commented 4 years ago

We have been making a lot of progress: Tree-shakeable version of firebase-app and firebase-functions are code complete, Auth is being rewritten from the ground up and Firestore's rewrite is a couple weeks away from being released.

GriffinJohnston commented 4 years ago

@schmidt-sebastian That's amazing news - thank you for the update!

schmidt-sebastian commented 4 years ago

We are still making some refinements (particularly in the Query class), but we would appreciate early feedback on our API: https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/exp/index.d.ts

maheshkumar2150 commented 4 years ago

I can't wait.

pierrebiver commented 4 years ago

Same, very excited to see those improvements. Is there any breaking change regarding the auth lib ?

IamManchanda commented 4 years ago

I made this practice project https://crown-clothing-ecom-preact.web.app/ (udemy course learnings) where I used firebase and I can't wait my project to optimize with reduced bundle after optimization that are being told by @schmidt-sebastian :)

maheshkumar2150 commented 4 years ago

I made this practice project https://crown-clothing-ecom-preact.web.app/ (udemy course learnings) where I used firebase and I can't wait my project to optimize with reduced bundle after optimization that are being told by @schmidt-sebastian :)

OFFTOPIC : May i know Which course did you follow?

blasco commented 4 years ago

@schmidt-sebastian when will this be available?

schmidt-sebastian commented 4 years ago

I am working on this full time but it is hard for me to predict what "weeks". I am 99% confident we are talking about single digit weeks and I will try to keep it to "low single digit weeks".

wceolin commented 4 years ago

@schmidt-sebastian Thanks for working on this. It will be a huge improvement to the library.

maheshkumar2150 commented 4 years ago

No words. Keep up your good work.

Is it possible to use any REST API for Cloud Firestore? (Only for web)

wiesson commented 4 years ago

Is it possible to use any REST API for Cloud Firestore? (Only for web)

I think that is more a question for stackoverflow, but what do you mean by "any" Rest API? You could make use of functions to build your own Rest API.

maheshkumar2150 commented 4 years ago

Not any. I am sorry. Without using functions, is there any official Rest API for cloud firestore? Using functions will cost double the price.

schmidt-sebastian commented 4 years ago

Along with the tree-shakeable client, we are also preparing a "Lite" SDK that uses the Rest API and will be much smaller in size, albeit without persistence or snapshot listeners.

samuelgozi commented 4 years ago

Along with the tree-shakeable client, we are also preparing a "Lite" SDK that uses the Rest API and will be much smaller in size, albeit without persistence or snapshot listeners.

You can use my code. It’s open source πŸ˜‰

samuelgozi commented 4 years ago

@maheshkumar2150 not official but you can use my libs for that until the official one arrives.

maheshkumar2150 commented 4 years ago

@maheshkumar2150 not official but you can use my libs for that until the official one arrives.

Good work. I am thinking to use yours.

Just one doubt. Is it like api? Have you written/hosted this in any server? Because, i want to just know how will it affect the traffic and perform on bigger sites?

samuelgozi commented 4 years ago

@maheshkumar2150 its a client side JS library, so other than including it in your bundle on the front end nothing else is needed. And it is very small and performs very well. I'm confident that in that regard there is not much to improve.

maheshkumar2150 commented 4 years ago

Thank you so much. How genius you are!

maheshkumar2150 commented 4 years ago

@maheshkumar2150 its a client side JS library, so other than including it in your bundle on the front end nothing else is needed. And it is very small and performs very well. I'm confident that in that regard there is not much to improve.

I am started to work with your library. If the official version is launched, will the coding work? Do i have to redo all the work again?

wilhuff commented 4 years ago

Please, let's keep discussion on topic. There are many people on this thread that are listening for updates about the official libraries. Ongoing discussion about alternatives should take place elsewhere.

maheshkumar2150 commented 4 years ago

Please, let's keep discussion on topic. There are many people on this thread that are listening for updates about the official libraries. Ongoing discussion about alternatives should take place elsewhere.

I opened this issue on 2019 October. I am very happy the team is working to fix the problem. I am paying firebase these days and i really have to fix the issue on my web apps. (Slow loading because of the size firestore)

@samuelgozi is promising and i don't want any issue on apps until official is launched. I believe i am the one who is waiting for very long time for the officials to come up with the minimized size than others.

Not taking this topic to off topic. Just two/three chats are not going to spoil and it might help others. Everyone in the end is going to use the official release.

figmentc commented 4 years ago

Along with the tree-shakeable client, we are also preparing a "Lite" SDK that uses the Rest API and will be much smaller in size, albeit without persistence or snapshot listeners.

This would be awesome. Will the Lite sdk encompass other firebase libraries aside from firestore? Namely auth as it has implications with Firestore security rules.

schmidt-sebastian commented 4 years ago

Lite will work with Firebase Auth.

GriffinJohnston commented 4 years ago

I'm so excited that you guys are releasing an official "lite" version. Persistence and real-time are awesome features, but the majority of projects probably don't need them, and it doesn't feel great carrying all that weight around for no reason. It feels like the FB team is listening to developers and moving in the right direction. Appreciate cha.

wenzf commented 4 years ago

Without using functions, is there any official Rest API for cloud firestore? @maheshkumar2150

Firestore can be accessed with a Rest API:

MALIK-0 commented 4 years ago

Hey guys are there any news on this? I'm doing some Svelte Project and wanted to use Firestore. I dropped my jaw after I saw the increase of about 450kb :D

@schmidt-sebastian Can you give an estimate about the file size of the upcoming version? Also it would be nice to know if you recommend using the current version of Firestore and then swapping to the new version (I'm asking because of breaking changes).

Last and final question. Is the Real Time Database significant smaller? For my case, I could also go with Real Time Database.

Thanks and have a nice day πŸ‘

schmidt-sebastian commented 4 years ago

I need a couple more days to work on this and am waiting on some code reviews. We are currently going through performance reviews and hence everyone is 110% busy doing non-code work.

Here are some size samples:

getDoc (Lite): 40 kB (13 kB gzipped) vs. 309 kB today (85 kB gzipped) setDoc (Lite): 43 kB (14 kB gzipped) vs. 309 kB today (85 kB gzipped) getDoc+setDoc (Lite): 51 kB (16 kB gzipped) vs. 309 kB today (85 kB gzipped) getDoc: 158 kB (51 kB gzipped) vs. 309 kB today (85 kB gzipped) getDocFromCache: 117 kB (38 kB gzipped) vs. 309 kB today (85 kB gzipped) setDoc: 158 kB (51 kB gzipped) vs. 309 kB today (85 kB gzipped) getDoc+setDoc: 163 kB (53 kB gzipped) vs. 309 kB today (85 kB gzipped) onSnapshot 160 kB (51 kB gzipped) vs. 309 kB today (85 kB gzipped)

These are the bundle sizes of Firebase App + Firestore using ES5/IIEFE with Rollup & terser. As stated, Firebase Auth is not ready yet. I am still working on tearing getDoc and setDoc apart even more, which should further reduce the size of the individual imports.

maheshkumar2150 commented 4 years ago

hi

how is it going? any news for us?

schmidt-sebastian commented 4 years ago

Okay, here we go. Huge heads up: The release I am about to talk about is VERY experimental. We have not tested it thoroughly in any way. It does not work with Firebase Auth (as the auth rewrite is not yet ready), so we recommend testing against the Emulator. We only published this release now since I am going on vacation next week and you have all been waiting for years :)

You can install the modular Firestore SDK from npm: npm install firebase@exp. The only products we have available so far are @firebase/app, @firebase/functions, @firebase/firestore. @firebase/auth and @firebase/storage are likely next, with all others after.

Sample usage:

import { initializeApp } from '@firebase/app';

// Release with latency compensation, snapshot listeners and cache
import { getFirestore, doc, getDoc, setDoc } from '@firebase/firestore';

// Or Lite SDK (which uses Rest API, offers no cache or listeners and is much smaller)
import { getFirestore, doc, getDoc, setDoc } from '@firebase/firestore/lite';

const app = initializeApp({ /* ... */ });

async function main() {
    const db = getFirestore(app);
    const doc1 = doc(db, 'coll/doc');
    await setDoc(doc1, {});
    const snapshot = await getDoc(doc1);
    console.log(snapshot.data());
}

main();

There are still some major TODOs to make the SDK more tree-shakeable, but at this point we are mostly looking for comments on the API surface. The best "documentation" is https://github.com/firebase/firebase-js-sdk/blob/master/docs-exp/index.md. You can also take a look at the TypeScript definition files https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/lite-types/index.d.ts (Lite SDK) and https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/exp-types/index.d.ts (Full SDK)

We will also provide a compatibility layer that will allow you to migrate your code slowly from the existing API to the new API.

hamishjohnson commented 4 years ago

enjoy your holiday, you deserve it!

spencerbn commented 4 years ago

Any updates on the auth changes?

Feiyang1 commented 4 years ago

@SpencerLawrenceBrown We have merged it into master, and is in the final stage before making an alpha release. Please stay tuned!

HunterJoey commented 4 years ago

@Feiyang1 Are the team waiting for FirebaseSummit on October 27-28 to release this update?

samtstern commented 4 years ago

@schmidt-sebastian @Feiyang1 any reason we have both this and #332 open? Maybe we should consolidate the discussion on #332 now that the exp libraries are getting closer to reality.

Feiyang1 commented 4 years ago

yeah, we will track it in https://github.com/firebase/firebase-js-sdk/issues/332. Closing