Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
**Learning:** Using `Array.from(map.values()).map(...)` creates an unnecessary intermediate array which wastes memory allocation and garbage collection time, particularly for frequently re-rendered components handling large collections.
**Action:** Use a `for...of` loop over `map.values()` to iterate and push mapped elements directly into the final array for O(1) memory and avoiding intermediate array allocations.

## 2026-07-09 - [Array density check optimization]
**Learning:** [Using Array.from().every() to check for array density creates O(N) intermediate array allocations which add unnecessary garbage collection overhead on the critical path.]
**Action:** [Use a standard for-loop with an early return (i in value) for an O(1) memory and faster check.]

## 2026-03-12 - O(1) early exit for confidence level
**Learning:** Using `.reduce()` unconditionally iterates over the entire array for operations with an absolute bound (e.g. finding if there's any 'low' confidence section).
**Action:** Replace unconditional `.reduce()` with a `for...of` loop and early `break` to short-circuit upon finding the minimum possible bound, changing O(N) worst-case into an O(K) best-case execution, yielding measurable performance gains on large documents.
9 changes: 8 additions & 1 deletion packages/shared-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,14 @@ function isRecord(value: unknown): value is Record<string, unknown> {

/** Documented. */
function isDenseArray(value: unknown): value is unknown[] {
return Array.isArray(value) && Array.from({ length: value.length }, (_, index) => index in value).every(Boolean);
if (!Array.isArray(value)) return false;
// Performance: Avoid O(N) allocation of intermediate array from Array.from()
for (let i = 0; i < value.length; i++) {
if (!(i in value)) {
return false;
}
}
return true;
}

/** Documented. */
Expand Down
Loading