Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An implementation of the exact same app in Firestore, AWS Datastore, PouchDB, RxDB and WatermelonDB

License

NotificationsYou must be signed in to change notification settings

pubkey/client-side-databases

Repository files navigation

In this project I have implemented the exact same chat application with different local first database technologies.You can use it to compare metrics and learn about the differences. The chat app is a web basedangular application, with functionality similar to Whatsapp Web.

chat app

Implemented Databases:

  • AWS Amplify Datastore
  • Firebase Firestore
  • PouchDB with IndexedDB adapter & CouchDB replication
  • RxDB LokiJS with LokiJS Storage & GraphQL replication
  • RxDB Dexie.js with Dexie.js Storage & GraphQL replication
  • WatermelonDB with LokiJS adapter (no backend sync atm)

Metrics

All metrics are measured automatically via code in a browser tests (chrome:headless). The results heavily depend on the developers device. You should compare the values relative to another and not as absolute values. Also you might want to create new metrics that better represent how you would use the respective database.

You can reproduce these values by runningsh measure-metrics.sh in the root folder.

Metric \ Projectawsfirebasepouchdbrxdb-dexierxdb-lokijswatermelondb
First angular component render231ms259ms219ms188ms207ms202ms
Page load time289ms207ms275ms250ms267ms259ms
First full render390ms746ms826ms473ms595ms275ms
Insert one message16ms262ms16ms18ms8ms5ms
Inserting 20 messages one after another433ms4639ms241ms223ms167ms107ms
Inserting 20 messages in parallel105ms3749ms88ms226ms37ms104ms
Message insert to message list change39ms17ms129ms18ms7ms4ms
Message search query time362ms210ms186ms37ms22ms23ms
First full render with many messages438ms852ms1288ms636ms606ms304ms
Storage usage239kb427kb1971kb1089kb2742kb2164kb
Bundle size, plain JavaScript1833kb952kb791kb1075kb1067kb955kb
Bundle size, minified+gzip421kb235kb190kb266kb254kb217kb

Metrics Explanation

  • Page load time: How long does it take to download and parse the JavaScript bundle.
  • First angular component render: How long does it take for the first angular component to be rendered.
  • First full render: How long does it take until all relevant data is displayed for the first time.
  • Insert one message: How long does it take to insert a single message.
  • Inserting 20 messages one after another: How long does it take to insert 20 messages in serial.
  • Inserting 20 messages in parallel: How long does it take to insert 20 messages in parallel.
  • Message insert to message list change: How long does it take until a new message is rendered to the dom.
  • User change to message list change: How long does it take from changing the user to the displaying of the new messages list.
  • Message search query time: How long does it take to search for a given message by regex/like-operator.
  • First full render with many messages: Time to first full render when many messages exist.
  • Storage usage: Size of the stored IndexedDB database after inserting the full test dataset.
  • Bundle size, plain #"auto">

    Investigations

Why is LokiJS so much faster?

WatermelonDB and the RxDB-LokiJS project use theLokiJS database as storage, which is anin memory database that regularly persists the data to IndexedDB either on interval, or when the browser tab is closed. By doing so,less slow IndexedDB transaction are used. Keeping and processing the data in memory has the benefit of being much faster, but it also has its downsides:

  • Initial page load is much slower when much data is already stored in the database, because all data must be loaded before any database operation can be done.
  • All data must fit into memory.
  • Data can be lost when the JavaScript process is killed ungracefully like when the browser crashes or the power of the PC is terminated.
  • There is no multi-tab-support with plain LokiJS. The data is not shared between multiple browser tabs of the same origin. RxDB handles that by addingits own multi tab handling via theBroadcastChannel module.

Why is Firebase so slow on first render?

On the first page load, Firebase ensures that the local data is equal to the server side state. This means that the client has to be online at application startup which is the reason why Firebase is not completely offline first. To ensure the equalness of client side data, Firebase has to perform several requests to the backend, before the database will respond to queries. This makes the inital page load slow, and it becomes even more slower, the more data exists and has to be validated.

Why is PouchDB so slow?

For the PouchDB and RxDB (with PouchDB storage) I used theold Indexeddb adapter.It is much less optimized than thenew adapter, but the new one made problems with returning the correct query results.Theses problems have been fixed on the PouchDB master branch, but I have to wait for the next PouchDB release. I will update the repo when this change can be done.

Why does AWS Datastore need so much less storage space?

AWS Datastore does not save any metadata together with the documents. Instead only the plain documents are stored in IndexedDB. They can do this because they only allow simple queries and do not keep a local version history.

Feature Map

Feature \ Projectawsfirebasepouchdbrxdb-lokijsrxdb-dexiewatermelondb
Offline FirstNo, login requiredPartially, must be online on first page loadYesYesYesYes
Realtime ReplicationYesYesYesYesYesPartially, must be implemented by hand
Multi Tab SupportYesYesNoYesYesPartially, relies on online sync
Observable QueriesNoYesNoYesYesYes
Complex QueriesNoYesYesYesYesYes
Client Side EncryptionNoNoYesYesYesNo
Schema SupportYesNoNoYesYesYes
Custom BackendNoNoNoYesYesYes
Custom Conflict HandlingYesNoYesYesYesNo

Starting the projects

All sub-projects use the same port and so cannot be started in parallel.

Installation

  • You must haveinstalled Node.js
  • Clone this project
  • In the root folder, runnpm install to install the dependencies.
  • In the root folder, runnpm run build to build all projects.

Firebase Firestore

  • Runnpm run start:firebase to start the mock server and the production build frontend.

  • Or runnpm run dev:firebase to start the mock server and the development frontend server.

  • Openhttp://localhost:3000/ to browse the frontend.

AWS Amplify & Datastore

The official AWS mock doesnot allow a live replication at this point. So you first have to setup an amplify project in the./projects/aws folder by usingthis tutorial

  • Runnpm run start:aws to start the mock server and the production build frontend.

  • Or runnpm run dev:aws to start the mock server and the development frontend server.

  • Openhttp://localhost:3000/ to browse the frontend.

PouchDB

  • Runnpm run start:pouchdb to start the mock server and the production build frontend.

  • Or runnpm run dev:pouchdb to start the mock server and the development frontend server.

  • Openhttp://localhost:3000/ to browse the frontend.

RxDB LokiJS

  • Runnpm run start:rxdb-lokijs to start the mock server and the production build frontend.

  • Or runnpm run dev:rxdb-lokijs to start the mock server and the development frontend server.

  • Openhttp://localhost:3000/ to browse the frontend.

RxDB Dexie.js

  • Runnpm run start:rxdb-dexie to start the mock server and the production build frontend.

  • Or runnpm run dev:rxdb-dexie to start the mock server and the development frontend server.

  • Openhttp://localhost:3000/ to browse the frontend.

WatermelonDB

  • Runnpm run start:watermelondb to start the mock server and the production build frontend.

  • Or runnpm run dev:watermelondb to start the mock server and the development frontend server.

  • Openhttp://localhost:3000/ to browse the frontend.

TODOs

Pull requests are welcomed. Please help implementing more examples:

  • Meteor (with the IndexedDB offline first plugin).
  • WatermelonDB backend replication.
  • AWS Ampflify local backend mock with realtime replication.
  • GunDB.

About

An implementation of the exact same app in Firestore, AWS Datastore, PouchDB, RxDB and WatermelonDB

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp