diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..fca09d1 --- /dev/null +++ b/.jules/bolt.md @@ -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. diff --git a/bar.c b/bar.c index 8476144..84deaa0 100644 --- a/bar.c +++ b/bar.c @@ -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); @@ -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; }