decred / politeia

ISC License
110 stars 75 forks source link

comments: Cache final timetamps. #1619

Closed amass01 closed 2 years ago

amass01 commented 2 years ago

This diff improves the performance of retrieving comment timestamps. It uses the key-value store to cache final timestamps which have been timestamped on the DCR chain as the performance of evaluating it on runtime is proportional to the tree size which makes it unacceptably slow in prod where the trees has ~30k leaves.

Benchmark:

I have tested the performance improvements of this commit locally with a proposal which has a tlog tree with ~10k leaves(comments), they are quite noticeable.

Before:

 $ pictl commenttimestamps 4178f2f 1 ... 100 --timer
Fetched 100/100 timestampes
---Timer Stats---
  Start  : 12 Jan 2022 11:17:13am
  Stop   : 12 Jan 2022 11:17:21am
  Elapsed: 10.50117024s

After:

$ pictl commenttimestamps 4178f2f 1 ... 100 --timer
Total number of comments: 100, fetched: 100, timestamped: 100, not timestamped: 0
---Timer Stats---
  Start  : 19 Jan 2022 11:27:55pm
  Stop   : 19 Jan 2022 11:27:55pm
  Elapsed: 206.05327ms

Part of #1538.

amass01 commented 2 years ago

Needs unit test for all helper functions in cmds.go

amass01 commented 2 years ago

Needs unit test for all helper functions in cmds.go

Done.