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 @@
## 2024-10-23 - Blocking Animations
**Learning:** The `animateclient` function uses `usleep(15000)` inside a `while` loop, which blocks the single-threaded X11 event loop. This causes the entire window manager to freeze during any window animation.
**Action:** Future optimizations should focus on refactoring this to use an event-based non-blocking animation system, possibly using a timer or `XNextEvent` with timeouts.
18 changes: 15 additions & 3 deletions bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,19 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
char *text;
char *p;

/* Optimization: Use stack allocation for common status text lengths (<1024)
to avoid malloc overhead in hot path. Fallback to malloc for larger strings. */
char buf[1024];
int use_malloc = 0;

len = strlen(stext) + 1;
if (!(text = (char *)malloc(sizeof(char) * len))) {
die("malloc");
if (len > sizeof(buf)) {
if (!(text = (char *)malloc(sizeof(char) * len))) {
die("malloc");
}
use_malloc = 1;
} else {
text = buf;
}
p = text;
memcpy(text, stext, len);
Expand Down Expand Up @@ -194,7 +204,9 @@ int drawstatusbar(Monitor *m, int bh, char *stext) {
}

drw_setscheme(drw, statusscheme);
free(p);
if (use_malloc) {
free(p);
}

return ret;
}
Expand Down