perf(usage-store): loadUsageRecords reads the entire usage.jsonl into memory before filtering
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- desktop, performance
Research direction
Start in apps/desktop/src/main/usage/store.ts at loadUsageRecords, especially lines 176–193, and trace how fromTs, toTs, and agentId are applied. Measure a time-range query against a growing usage.jsonl; done means preserving those filters without loading and parsing discarded records.
Written by the indexing model from the issue text.
Description
Problem
apps/desktop/src/main/usage/store.ts L176–193
const lines = readFileSync(USAGE_FILE, 'utf8').split('\n').filter(Boolean);
// then a for-loop applies fromTs/toTs/agentId filters
usage.jsonl grows over time (the comment notes ~1–2 MB per 10,000 requests), but every query reads the entire file into memory, parses all lines, then discards most of them. For time-range queries such as "today's usage," the vast majority of records are thrown away.
Suggested fix
Maintain an in-memory index sorted by timestamp (line offset → ts) and use binary search to locate the fromTs starting point, reading and parsing only the relevant segment. Alternatively, switch to streaming reads for large files.
- Dominant language
- TypeScript
- Stars
- 120
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from unbug/tday
-
performance
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
perf(history-store): saveStore uses JSON.stringify with 2-space indent, bloating file size by 30–50%Openperformance
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
performance
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
perf(usage-store): Math.max(...tsValues) spread overflows V8 argument stack on large record setsOpenperformance
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
performance
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
TomerAberbach/profiler-md#733 ·
Maintainers usually reply within 1 day
-
bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
brentspine/brents-toasts#143 ·
-
🐛 bug 🗺️ DB Models & Ops
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
LibreChat-AI/LibreChat#17214 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Wavvon/Wavvon-clients#136 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
umami-software/umami#4637 ·
Maintainers usually reply within 3 days