perf(usage-store): Math.max(...tsValues) spread overflows V8 argument stack on large record sets
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- desktop
Research direction
Start in apps/desktop/src/main/usage/store.ts at lines 153–154 and trace how records are used to calculate spanMs. Replace the large-record calculation without relying on spread arguments or the intermediate array, then verify that records over 65,536 entries avoid the RangeError and still produce the correct span.
Written by the indexing model from the issue text.
Description
Problem
apps/desktop/src/main/usage/store.ts L153–154
const tsValues = records.map((r) => r.ts); // intermediate array
const spanMs = tsValues.length > 1
? Math.max(...tsValues) - Math.min(...tsValues) // ← spread
: 0;
Math.max(...array) passes array elements as function arguments via spread. V8's function call argument limit is ~65,536. When records exceeds that count, a RangeError: Maximum call stack size exceeded is thrown.
Suggested fix
Replace the spread with a reduce or for loop:
let minTs = Infinity, maxTs = -Infinity;
for (const r of records) {
if (r.ts < minTs) minTs = r.ts;
if (r.ts > maxTs) maxTs = r.ts;
}
This also eliminates the intermediate tsValues array allocation, saving one O(n) pass.
- Dominant language
- TypeScript
- Stars
- 120
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
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
-
performance
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
performance
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100