Fireship · @fireship
Firebase Database Performance Profiling
Uploaded September 19, 2017 · Length 5:56
Summary
This video teaches how to use the Firebase profiler tool to optimize database performance, including profiling write speed, reading data, and making multiple queries.
- firebase database performance
- firebase profiler tool
- database optimization
- firebase latency
- firebase indexing
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
database profiling is critical for
- 0:02
finding bottlenecks or other issues that
- 0:04
might be degrading the user experience
- 0:06
in this episode we're going to look at
- 0:08
the built in firebase profiler tool
- 0:10
which will give us a breakdown of the
- 0:12
memory and speed performance of our
- 0:14
database this tutorial is done in the
- 0:16
context of an angular application but in
- 0:18
just as easily be applied to the
- 0:20
firebase JavaScript SDK if you're just
- 0:23
getting started with firebase you'll
- 0:24
need to install the firebase tools
- 0:26
command-line interface and then
- 0:28
initialize your project by running in
- 0:30
firebase and knit to demonstrate this
- 0:34
feature we're going to read and write a
- 0:35
bunch of weather data in the firebase
- 0:37
database which I've acquired here from
- 0:39
the dark sky API so I went ahead and
- 0:41
parsed this JSON into JavaScript and
- 0:43
then I'm importing it in an angular
- 0:45
component here when we save the data to
- 0:48
firebase it's going to look like this a
- 0:49
big object with its own nested objects
- 0:52
and arrays not something you would
- 0:53
consider optimize for efficiency in a no
- 0:56
sequel database then back in the angular
- 0:59
component I'm going to create an
- 1:00
observable stopwatch which will help us
- 1:03
determine the actual latency the user
- 1:05
sees on the front-end so we can start
- 1:07
the stopwatch as soon as we make a
- 1:08
request and then as soon as firebase
- 1:10
returns us an actual object we'll stop
- 1:12
the stopwatch and then all display that
- 1:14
number in milliseconds on the front end
- 1:16
we can do this in rxjs by creating an
- 1:18
observable interval that ticks every one
- 1:20
millisecond and to finish the stopwatch
- 1:22
we just call unsubscribe on it then
- 1:25
going down into the angular component we
- 1:28
can just create a new instance of the
- 1:29
stopwatch and then inject the angular
- 1:32
fired database and the constructor then
- 1:34
the first thing we'll profile is the
- 1:36
write speed to the real-time database
- 1:38
first I'll quickly show you the plain
- 1:39
firebase SDK code basically we just make
- 1:42
a reference to the database and then
- 1:44
push new objects to it then back in
- 1:47
angular we'll do the same thing but
- 1:48
using that angular fire to wrapper and I
- 1:51
want to push 20 objects to the database
- 1:53
so I use a for loop here and then for
- 1:55
each iteration du DB push that's going
- 1:58
to return a promise so once we get to


