Skip to content
Draft
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 @@
## 2026-01-25 - Stack vs Heap in Hot Paths
**Learning:** `drawstatusbar` in `bar.c` allocates and frees a buffer on every redraw. Since the buffer size is bounded by `stext` (1024 bytes), this is unnecessary overhead.
**Action:** Use stack allocation for small, bounded buffers in frequent operations to avoid allocator overhead and fragmentation.
13 changes: 6 additions & 7 deletions bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
int len;
int cmdcounter;
short isCode = 0;
char *text;
char *p;
char text_buf[1024];
char *text = text_buf;

len = strlen(stext) + 1;
if (!(text = (char *)malloc(sizeof(char) * len))) {
die("malloc");
if (len > sizeof(text_buf)) {
len = sizeof(text_buf);
}
p = text;
memcpy(text, stext, len);
text[len - 1] = '\0';

/* compute width of the status text */
w = 0;
Expand All @@ -88,7 +88,7 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
} else {
isCode = 0;
}
text = p;
text = text_buf;
statuswidth = w;
w += 2; /* 1px padding on both sides */
ret = x = m->ww - w - getsystraywidth();
Expand Down Expand Up @@ -194,7 +194,6 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
}

drw_setscheme(drw, statusscheme);
free(p);

return ret;
}
Expand Down