Large Amounts of Deleted Records causing api calls to be slower
- Dominant language
- Python
- Stars
- 8
- Forks
- 2
- Avg merge
- 14h 34m
- Merged PRs (30d)
- 46
Description
Right now, if a request has many deleted records (~1400+), it will cause other api calls (e.g. annotations) to be slower since we need to join with deleted records table to filter out all the deleted records. This is already happening in regular dev and test so it will happen in production as well
[Private Zenhub Image](https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBd1BqQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--fce39f992e3bab7072280151e80be203b3e6c7c7/image.png)
[Private Zenhub Image](https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBd1RqQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--22ce9e6f152bb7d881ec836499ee599ebcc33086/image.png)
We have tried to pinpoint the cause of this issue however it needs more investigation. A request with few to zero deleted records takes 500-700 ms for backend code to run and 1-1.7 s total for annotations api call,
[Private Zenhub Image](https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBeERqQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--e867b54102d58a59f947c168e09d248830f8a94b/image.png)
while a request with 1400+ deleted records takes 2.5 - 3 s for backend code to run and 6-7 seconds for the entire api call.
[Private Zenhub Image](https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBdy9qQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--3dd4bab55fb5354ce131a158643ceb03cf0a2e11/image.png)
[Private Zenhub Image](https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBeEhqQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--98fbac7e567cdf0562b24227f07bd894b6421fb5/image.png)
However the increase in backend execution doesn't explain why the total time goes up so much since it is only an increase of 2-2.5 s for backend execution but an increase of of 5-6 s for the total api call. You can see from the screenshot that the payload sizes are also similar so there is no reason why network latency should increase much.
[Private Zenhub Image](https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBdzNqQVE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--c9ca97844a37446cb9cc7995a0677a562808fb00/image.png)
We may need to reengineer the deleted table to be more efficient since right now we are joining on filepath which is a text column with very long strings
Contributor guide
Research direction
Start by tracing the annotations API request and its join with the deleted records table, comparing requests with few deleted records against those with 1,400 or more. Done means the source of the extra backend and total-call time is identified and the filtering behavior remains correct after the performance issue is addressed.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, databases, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100