perf(dashboard): consolidate jq calls and buffer render output#17
Open
MuLinForest wants to merge 1 commit into
Open
perf(dashboard): consolidate jq calls and buffer render output#17MuLinForest wants to merge 1 commit into
MuLinForest wants to merge 1 commit into
Conversation
Replace 10 individual `jq` invocations per session with a single call
using `join("\u001f")` (ASCII Unit Separator, octal \037). This reduces
process forks from O(10n) to O(n) per render cycle.
Benchmark (100 iterations, 1 session file):
Old (10 jq calls): 16.9s real → ~169ms per render
New (1 jq call): 1.5s real → ~15ms per render
→ 11× faster per session
Using \u001f instead of @TSV (tab) also fixes a correctness bug: with
`IFS=$'\t' read`, consecutive empty fields (e.g. git_branch and
last_activity both empty) collapse into one separator, silently
shifting all subsequent fields — causing BRANCH to display the mem_kb
value instead. The non-whitespace Unit Separator preserves empty fields
correctly.
Use `_US=$(printf '\037')` instead of `$'\x1f'` for POSIX sh / dash
compatibility (Debian's /bin/sh is dash, which does not support the
`$'...'` escape syntax).
Buffer the entire frame in a subshell (`_frame=$(...)`) and flush it
atomically with a single `printf '\033[2J\033[H%s'`. This eliminates
visible partial-frame flicker caused by incremental line-by-line writes.
Co-Authored-By: MuLinForest <5525477+MuLinForest@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <claude-code@mulin.date>
MuLinForest
added a commit
to MuLinForest/claude-code-toolkit
that referenced
this pull request
Mar 26, 2026
…session_title in single jq call Resolve dashboard.sh conflict: add session_title to PR kayhaowu#17's consolidated jq read, removing the redundant individual jq calls from PR kayhaowu#15. Co-Authored-By: Claude Sonnet 4.6 <claude-code@mulin.date>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two rendering improvements to
dashboard.sh:1. Consolidate jq calls (11× faster per session)
Replace 10 individual
jqinvocations per session with a single call usingjoin("\u001f")(ASCII Unit Separator, octal\037).Benchmark (100 render iterations, 1 session file, Debian/Linux):
jqcallsjqcall→ 11× faster per session. The bottleneck is process fork overhead — each
jqinvocation is a fork+exec+read; with n sessions the old code did 10n forks per render.Using
\u001finstead of@tsv(tab) also fixes a correctness bug: withIFS=$'\t' read, consecutive empty fields (e.g.git_branchandlast_activityboth empty) collapse into one separator, silently shifting all subsequent fields — causing BRANCH to display themem_kbvalue instead of the git branch._US=$(printf '\037')is used instead of$'\x1f'for POSIX sh / dash compatibility (Debian's/bin/shis dash, which does not support the$'...'escape syntax).2. Buffer render output (flicker-free)
Buffer the entire frame in a subshell (
_frame=$(...)) and flush it atomically with a singleprintf '\033[2J\033[H%s'. This eliminates the visible partial-frame flicker caused by incremental line-by-line terminal writes interleaved with the kernel scheduler.Test plan
sh/dash(not justbash)