Fireship · @fireship

Firebase Database Performance Profiling

Uploaded September 19, 2017 · Length 5:56

Firebase Database Performance Profiling

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.

  1. 0:00

    database profiling is critical for

  2. 0:02

    finding bottlenecks or other issues that

  3. 0:04

    might be degrading the user experience

  4. 0:06

    in this episode we're going to look at

  5. 0:08

    the built in firebase profiler tool

  6. 0:10

    which will give us a breakdown of the

  7. 0:12

    memory and speed performance of our

  8. 0:14

    database this tutorial is done in the

  9. 0:16

    context of an angular application but in

  10. 0:18

    just as easily be applied to the

  11. 0:20

    firebase JavaScript SDK if you're just

  12. 0:23

    getting started with firebase you'll

  13. 0:24

    need to install the firebase tools

  14. 0:26

    command-line interface and then

  15. 0:28

    initialize your project by running in

  16. 0:30

    firebase and knit to demonstrate this

  17. 0:34

    feature we're going to read and write a

  18. 0:35

    bunch of weather data in the firebase

  19. 0:37

    database which I've acquired here from

  20. 0:39

    the dark sky API so I went ahead and

  21. 0:41

    parsed this JSON into JavaScript and

  22. 0:43

    then I'm importing it in an angular

  23. 0:45

    component here when we save the data to

  24. 0:48

    firebase it's going to look like this a

  25. 0:49

    big object with its own nested objects

  26. 0:52

    and arrays not something you would

  27. 0:53

    consider optimize for efficiency in a no

  28. 0:56

    sequel database then back in the angular

  29. 0:59

    component I'm going to create an

  30. 1:00

    observable stopwatch which will help us

  31. 1:03

    determine the actual latency the user

  32. 1:05

    sees on the front-end so we can start

  33. 1:07

    the stopwatch as soon as we make a

  34. 1:08

    request and then as soon as firebase

  35. 1:10

    returns us an actual object we'll stop

  36. 1:12

    the stopwatch and then all display that

  37. 1:14

    number in milliseconds on the front end

  38. 1:16

    we can do this in rxjs by creating an

  39. 1:18

    observable interval that ticks every one

  40. 1:20

    millisecond and to finish the stopwatch

  41. 1:22

    we just call unsubscribe on it then

  42. 1:25

    going down into the angular component we

  43. 1:28

    can just create a new instance of the

  44. 1:29

    stopwatch and then inject the angular

  45. 1:32

    fired database and the constructor then

  46. 1:34

    the first thing we'll profile is the

  47. 1:36

    write speed to the real-time database

  48. 1:38

    first I'll quickly show you the plain

  49. 1:39

    firebase SDK code basically we just make

  50. 1:42

    a reference to the database and then

  51. 1:44

    push new objects to it then back in

  52. 1:47

    angular we'll do the same thing but

  53. 1:48

    using that angular fire to wrapper and I

  54. 1:51

    want to push 20 objects to the database

  55. 1:53

    so I use a for loop here and then for

  56. 1:55

    each iteration du DB push that's going

  57. 1:58

    to return a promise so once we get to