Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/afk/__bench__/README.md

Raw
Rendered preview

AFK widget benchmark

Scope and rationale

The sprite renderer already emits at most one single-cell block or space per available column. Scanning those ANSI-styled rows again with truncateToWidth adds work without changing output. Only the two variable-width text headers need terminal-width truncation. The optimization preserves sprite pixels, styling, animation cadence, state transitions, and disposal.

The target is the AFK widget present in the working tree, including its pre-existing sprite redesign, not the older ASCII widget in HEAD. Pre-existing changes remain uncommitted and are not attributed to this optimization.

Method

Use //extensions/afk:bench through Mise. Optional arguments: --baseline <module.ts>, --profile <output.cpuprofile>, --output <report.json>. A baseline module must export createAfkWidget and resolve its runtime imports independently of the snapshot directory. Without --baseline, both sides use current code as a noise control. --profile records the baseline using Node's V8 CPU profiler before unprofiled comparisons. Keep snapshots, profiles, and reports in OS temp space.

The host renders the actual widget at width 80 with a real dark truecolor Pi theme on each redraw request. Node's mock clock advances both timers and Date from zero in 1,024 steps of 125 ms, representing 128 seconds. Mocking Date is necessary for sprite motion and elapsed-state transitions; a style stub omits the measured ANSI cost. The awake workload begins watchful and becomes bored after 45 seconds; the asleep workload remains napping. This measures timer dispatch, widget rendering, joining, and frame comparison, not full Pi layout, terminal I/O, or model inference.

Three warmup workloads per implementation are discarded before 31 paired measurements, alternating execution order. Pairs outside either implementation's 1.5-IQR wall-time bounds are removed, with counts reported. The report includes unfiltered savings, retained mean/SD, CPU time, redraw counts, and paired-bootstrap 95% confidence intervals from 10,000 seeded resamples. Three independent process runs check sensitivity to process-level variation. Intervals describe within-process workloads, not deployment-wide performance.

Recorded evidence

Environment: Node 26.10.0, Pi TUI 1.4.0, CachyOS Linux x64, Ryzen 5 5600X. Runs were sequential; CPU frequency, background system activity, and scheduler placement were not controlled. No dependencies, system configuration, or build configuration changed.

The pre-change V8 profile collected 6,466 samples. truncateToWidth accounted for 3,101 samples (48.0%); ANSI extraction, grapheme width, and ANSI length helpers added 1,108 samples (17.1%). Garbage collection accounted for 799 samples (12.4%). The corrected harness's baseline-versus-itself awake control had a savings interval of [-2.1%, 4.4%], spanning zero.

Three baseline/candidate process runs, each with 31 paired samples:

  • Awake retained mean wall time: 568.1 → 60.8 ms, 566.1 → 62.3 ms, 564.2 → 60.1 ms.
  • Awake baseline SD: 18.8, 19.7, 18.4 ms; candidate SD: 16.6, 17.0, 16.6 ms.
  • Awake unfiltered savings: 89.3%, 89.0%, 89.3%.
  • Awake retained 95% savings intervals: [88.4%, 90.2%], [88.0%, 90.0%], [88.3%, 90.3%].
  • Awake removed pairs: 0, 0, 1.
  • Awake mean CPU time: approximately 562–566 → 61–63 ms.
  • Asleep retained mean wall time: 53.9 → 15.5 ms, 54.0 → 15.1 ms, 53.5 → 15.2 ms.
  • Asleep baseline SD: 3.6, 2.6, 4.0 ms; candidate SD: 11.2, 11.3, 10.9 ms.
  • Asleep unfiltered savings: 71.3%, 72.0%, 71.6%.
  • Asleep retained 95% savings intervals: [63.3%, 78.9%], [64.4%, 79.5%], [63.7%, 79.4%].
  • Asleep removed pairs: 0, 0, 0.
  • Asleep mean CPU time: approximately 53–54 → 15–16 ms.

Every retained savings interval excludes zero; unfiltered results support the same effect despite substantial sleeping-workload variance. Awake redraws remain 1,024, including 814 unchanged frames; asleep redraws remain 128, including 13 unchanged frames. Reduced redraw scheduling is not part of this optimization.

Verification and limits

AFK tests passed before and after optimization: 46 passed, one optional package test skipped. The unchanged SHA256 oracle preserves exact styled output across 756 combinations of nine moods, two theme appearances, six timestamps, and seven widths. Existing semantic tests also check visible width, distinct moods, elapsed-state transitions, invalidation, and disposal. No snapshots or assertions were refreshed. No new visual design was introduced; interactive screenshot verification was not run. 256-color mode and a full Pi-terminal performance comparison remain unmeasured. These results establish lower simulated widget workload cost, not faster model inference, measured battery savings, or end-to-end Pi CPU percentages.

# AFK widget benchmark

## Scope and rationale

The sprite renderer already emits at most one single-cell block or space per available column.
Scanning those ANSI-styled rows again with `truncateToWidth` adds work without changing output.
Only the two variable-width text headers need terminal-width truncation.
The optimization preserves sprite pixels, styling, animation cadence, state transitions, and disposal.

The target is the AFK widget present in the working tree, including its pre-existing sprite redesign, not the older ASCII widget in HEAD.
Pre-existing changes remain uncommitted and are not attributed to this optimization.

## Method

Use `//extensions/afk:bench` through Mise.
Optional arguments: `--baseline <module.ts>`, `--profile <output.cpuprofile>`, `--output <report.json>`.
A baseline module must export `createAfkWidget` and resolve its runtime imports independently of the snapshot directory.
Without `--baseline`, both sides use current code as a noise control.
`--profile` records the baseline using Node's V8 CPU profiler before unprofiled comparisons.
Keep snapshots, profiles, and reports in OS temp space.

The host renders the actual widget at width 80 with a real dark truecolor Pi theme on each redraw request.
Node's mock clock advances both timers and `Date` from zero in 1,024 steps of 125 ms, representing 128 seconds.
Mocking `Date` is necessary for sprite motion and elapsed-state transitions; a style stub omits the measured ANSI cost.
The awake workload begins watchful and becomes bored after 45 seconds; the asleep workload remains napping.
This measures timer dispatch, widget rendering, joining, and frame comparison, not full Pi layout, terminal I/O, or model inference.

Three warmup workloads per implementation are discarded before 31 paired measurements, alternating execution order.
Pairs outside either implementation's 1.5-IQR wall-time bounds are removed, with counts reported.
The report includes unfiltered savings, retained mean/SD, CPU time, redraw counts, and paired-bootstrap 95% confidence intervals from 10,000 seeded resamples.
Three independent process runs check sensitivity to process-level variation.
Intervals describe within-process workloads, not deployment-wide performance.

## Recorded evidence

Environment: Node 26.10.0, Pi TUI 1.4.0, CachyOS Linux x64, Ryzen 5 5600X.
Runs were sequential; CPU frequency, background system activity, and scheduler placement were not controlled.
No dependencies, system configuration, or build configuration changed.

The pre-change V8 profile collected 6,466 samples.
`truncateToWidth` accounted for 3,101 samples (48.0%); ANSI extraction, grapheme width, and ANSI length helpers added 1,108 samples (17.1%).
Garbage collection accounted for 799 samples (12.4%).
The corrected harness's baseline-versus-itself awake control had a savings interval of [-2.1%, 4.4%], spanning zero.

Three baseline/candidate process runs, each with 31 paired samples:

- Awake retained mean wall time: 568.1 → 60.8 ms, 566.1 → 62.3 ms, 564.2 → 60.1 ms.
- Awake baseline SD: 18.8, 19.7, 18.4 ms; candidate SD: 16.6, 17.0, 16.6 ms.
- Awake unfiltered savings: 89.3%, 89.0%, 89.3%.
- Awake retained 95% savings intervals: [88.4%, 90.2%], [88.0%, 90.0%], [88.3%, 90.3%].
- Awake removed pairs: 0, 0, 1.
- Awake mean CPU time: approximately 562–566 → 61–63 ms.
- Asleep retained mean wall time: 53.9 → 15.5 ms, 54.0 → 15.1 ms, 53.5 → 15.2 ms.
- Asleep baseline SD: 3.6, 2.6, 4.0 ms; candidate SD: 11.2, 11.3, 10.9 ms.
- Asleep unfiltered savings: 71.3%, 72.0%, 71.6%.
- Asleep retained 95% savings intervals: [63.3%, 78.9%], [64.4%, 79.5%], [63.7%, 79.4%].
- Asleep removed pairs: 0, 0, 0.
- Asleep mean CPU time: approximately 53–54 → 15–16 ms.

Every retained savings interval excludes zero; unfiltered results support the same effect despite substantial sleeping-workload variance.
Awake redraws remain 1,024, including 814 unchanged frames; asleep redraws remain 128, including 13 unchanged frames.
Reduced redraw scheduling is not part of this optimization.

## Verification and limits

AFK tests passed before and after optimization: 46 passed, one optional package test skipped.
The unchanged SHA256 oracle preserves exact styled output across 756 combinations of nine moods, two theme appearances, six timestamps, and seven widths.
Existing semantic tests also check visible width, distinct moods, elapsed-state transitions, invalidation, and disposal.
No snapshots or assertions were refreshed.
No new visual design was introduced; interactive screenshot verification was not run.
256-color mode and a full Pi-terminal performance comparison remain unmeasured.
These results establish lower simulated widget workload cost, not faster model inference, measured battery savings, or end-to-end Pi CPU percentages.