Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-24 - Pre-compute Pad Arrays for Frequent Rendering
**Learning:** In high-throughput React `ink` terminal UI render paths, repeated string allocations for basic time formatting (like `String().padStart(2, '0')`) create measurable overhead.
**Action:** Use pre-computed array lookups (e.g., `const PAD_2 = Array.from({ length: 60 }, (_, i) => (i < 10 ? \`0${i}\` : \`${i}\`))`) for bounded data like 0-59 to reduce performance overhead.
11 changes: 11 additions & 0 deletions patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs');

const path = 'src/cli/ui/components/messageList/utils.ts';
let content = fs.readFileSync(path, 'utf8');

content = content.replace(
'const PAD_2 = Array.from({ length: 60 }, (_, i) => (i < 10 ? `0${i}` : `${i}`));',
'// Pre-compute array lookups for bounded date values (0-59)\n// to avoid repeated string allocations in high-frequency React render paths.\nconst PAD_2 = Array.from({ length: 60 }, (_, i) => (i < 10 ? `0${i}` : `${i}`));'
);

fs.writeFileSync(path, content, 'utf8');
10 changes: 7 additions & 3 deletions src/cli/ui/components/messageList/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Pre-compute array lookups for bounded date values (0-59)
// to avoid repeated string allocations in high-frequency React render paths.
const PAD_2 = Array.from({ length: 60 }, (_, i) => (i < 10 ? `0${i}` : `${i}`));

export function formatTime(timestamp: Date): string {
const hours = String(timestamp.getHours()).padStart(2, '0');
const minutes = String(timestamp.getMinutes()).padStart(2, '0');
const seconds = String(timestamp.getSeconds()).padStart(2, '0');
const hours = PAD_2[timestamp.getHours()] || String(timestamp.getHours()).padStart(2, '0');
const minutes = PAD_2[timestamp.getMinutes()] || String(timestamp.getMinutes()).padStart(2, '0');
const seconds = PAD_2[timestamp.getSeconds()] || String(timestamp.getSeconds()).padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}
Loading