1

What will be smaller to keep in Firestore and send to the client?

Array with a thousand items:

[
  {date: firestore.Timestamp.fromDate(new Date(Date.UTC(2020,2,25))), value: 1.1},
  {date: firestore.Timestamp.fromDate(new Date(Date.UTC(2020,2,26))), value: 1.2},
  {date: firestore.Timestamp.fromDate(new Date(Date.UTC(2020,2,27))), value: 1.3},
  {date: firestore.Timestamp.fromDate(new Date(Date.UTC(2020,2,28))), value: 1.4},
  // AND SO ON
]

VS

[
  {date: "2020-03-25", value: 1.1},
  {date: "2020-03-25", value: 1.2},
  {date: "2020-03-25", value: 1.3},
  {date: "2020-03-25", value: 1.4},
  // AND SO ON
]

QUESTION

My question is: is a firestore Timestamp larger/smaller than a text string "yyyy-mm-dd" ? Should I prefer one over the other?

NOTE: This will be sent to the client. That's why I'm looking to the smaller file size option.


UPDATE:

From: https://firebase.google.com/docs/firestore/storage-size

enter image description here

Does that mean a timestamp field takes 8 bytes (from the Date and time row on the table)?

And the "yyyy-mm-dd" would take 11 bytes? 10 encoded chars + 1?

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

1 Answers1

1

My question is: is a Firestore Timestamp larger/smaller than a text string "yyyy-mm-dd"?

Of course, a String that contains 10 characters is larger than a Date object.

The number of bytes taken to represent the string depends entirely on which encoding you use. Since Firestore uses UTF-8, a String that has this representation:

"2020-03-25"

Occupies 10 + 1 = 11 bytes while a Date object will always occupy 8 bytes.

Bear in mind that in Firestore is not always about the size as it's more about the functionality that you get. If you store the dates as Strings, you'll not be able to order your results, as the ordering is made lexicographically. When using a Date you can order either ascending or descending.

I have recently answered a relative similar question:

This might help you if you still consider storing the dates as strings.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • 2
    Thanks, Alex. To my current need, a simple text string would do the trick. The arrays will always be kept in order. So you think a Timestamp is definetely larger than a 10-char string? Could you take a look on the table I've added to the question? What does that table mean by `Date and time` ? Wouldn't it be a `Timestamp`? Thanks again – cbdeveloper Apr 01 '20 at 14:33
  • Yes, it's a timestamp. It's the opposite. Please check my updated answer. – Alex Mamo Apr 01 '20 at 14:46