HumanSignal / HumanSignal/label-studio
Slow performance with 100k images as links and with 10k images as base64 encoded
- Dominant language
- TypeScript
- Stars
- 28.3k
- Forks
- 3.7k
- Avg merge
- 14h
- Merged PRs (30d)
- 15
Description
**Describe the bug**
When working with 10.000+ tasks with base64-encoded images the project page and tasks overview page become very slow. Adding more projects or images this way makes it unworkable.
Please note that the actual labeling (when clicking on label all tasks) works fine and is fast.
**To Reproduce**
Steps to reproduce the behavior:
1. Using the Python SDK create 10.000+ tasks and in the `data['image']` field store the image in base64 as described [here](https://github.com/HumanSignal/label-studio/issues/6086).
2. Go to either the projects page or click on the project
3. Notice that loading takes long (over 15 seconds on our machines)
**Expected behavior**
Simply displaying the number of tasks in the project overview should not take that long. Also showing the tasks in the tasks list which uses pagination should not take that long.
**Environment (please complete the following information):**
- OS: Kubeflow, helm chart
- Label Studio Version 1.22.0
**Additional context**
I suspect the issue are the queries. When logging in to the database and running `\watch 2` this shows that the query that counts the tasks is taking >15 sec. When inspecting the query it does a `DISTINCT` operation on all fields of the tasks, including the `data` field that contains the BASE64-encoded image. This is probably the cause.
I looked at the source-code of LabelStudio but cannot directly see why `DISTINCT` is needed or why it needs to check all fields.
Below the query that is run when the projects overview is loading:
`SELECT COUNT(*) FROM (SELECT DISTINCT "task"."id" AS "col1", "task"."data" AS "col2", "task"."meta" AS "col3", "task"."project_id" AS "col4", "task"."created_at" AS "col5", "task"."updated_at" AS "col6", "task"."updated_by_id" AS "col7", "task"."is_labeled" AS "col8", "task"."allow_skip" AS "col9", "task"."overlap" AS "col10", "task"."file_upload_id" AS "col11", "task"."inner_id" AS "col12", "task"."total_annotations" AS "col13", "task"."cancelled_annotations" AS "col14", "task"."total_predictions" AS "col15", "task"."precomputed_agreement" AS "col16", "task"."comment_count" AS "col17", "task"."unresolved_comment_count" AS "col18", "task"."last_comment_updated_at" AS "col19" FROM "task" LEFT OUTER JOIN "task_completion" ON ("task"."id" = "task_completion"."task_id") WHERE ("task"."project_id" = 1 AND ((NOT "task"."is_labeled" AND NOT (EXISTS(SELECT 1 AS "a" FROM "task_completion" U1 WHERE (U1."completed_by_id" = 1 AND U1."task_id" = ("task"."id")) LIMIT 1))) OR "task_completion"."completed_by_id" = 1))) subq
`
Contributor guide
Assessment
This issue has not been assessed yet.