Skip to content

Performance and Benchmarks

jayjay181818 edited this page Nov 17, 2026 · 1 revision

Performance and Benchmarks

How Stockbar's resource use is measured, and what the 3.8.0 optimisation work found. The canonical sources are Scripts/README_PERFORMANCE.md (the tools) and EXPERIMENTAL_LOG.md (the record of the work and every measurement).

Read the numbers with care. Every figure on this page comes from the project's benchmark running on made-up data on one Mac: 11 holdings, 7,000 portfolio snapshots of 15 positions each and about 70,000 prices, with live providers switched off. Your figures will differ with your portfolio, your history and your Mac. The log itself says that figures from different days are not set side by side, because the machine's state drifts.

The four tools

All are run from the repository root. None needs administrator rights.

Question Tool
What is the app I am running using right now? Scripts/measure_performance.sh
What does this checkout use, on fixed data? Scripts/perf/benchmark.sh
Did a change make a difference? Scripts/perf/compare.sh
What is the Python helper's memory made of? Scripts/perf/helper_layers.py

A running app: measure_performance.sh

bash Scripts/measure_performance.sh                 # ten minutes
bash Scripts/measure_performance.sh --duration 60   # a quick look

Samples the running Stockbar and its Python helper: memory (the physical footprint, the figure Activity Monitor shows), how much of the time the helper was running, CPU seconds, wake-ups and disk writes per minute. It reads kernel counters and never pauses or signals the app. It is the only tool that sees the helper at work and real refreshes, so its figures depend on your portfolio, the network and the time of day: use it to look, not to compare two builds.

One build on fixed data: benchmark.sh

bash Scripts/perf/benchmark.sh --label my-change

It builds the Release configuration as a separate app (com.stockbar.acceptance) and runs it in the isolated acceptance mode: its own storage in a temporary folder, live providers off, no Keychain. Scripts/perf/make_fixture.py fills that storage with synthetic history. There is one warm-up launch, then five measured launches; the Mac and its display are kept awake meanwhile.

For every launch it records:

Figure What it is
app_footprint_mb_median Idle memory: physical footprint over a 60 s window that starts 75 s after launch
app_heap_allocated_mb Bytes the app holds allocated at the end of the window. Steadier than the footprint.
app_lifetime_peak_mb The most memory the app held at any point: launch, first window and history load
app_footprint_drift_mb Later half of the idle window against the earlier half (use a long --window)
app_cpu_s_per_min, app_wakeups_per_min Idle CPU time and CPU wake-ups
app_power_mw Idle CPU power, from the kernel's per-process energy estimate
app_cpu_s_before_window, app_energy_j_before_window CPU time and energy from launch to the start of the idle window
launch_to_window_s, launch_to_history_s Launch until the main window is on screen; until the stored history is loaded
helper_start_s, helper_start_cpu_s, helper_footprint_mb One start of the Python helper to the point it can take a request, with no network

Results, logs, memory samples and breakdowns are kept in build/bench/results/. A run that does not finish has no summary, but keeps the app's log as app-failed.log in the same place.

The refresh workload. The ordinary launches never refresh a price, because live providers are off. --refresh adds as many launches again for a refresh workload: after a settling period the script signals the app (SIGUSR1) and the app runs four "Refresh now" passes, 30 s apart, on made-up quotes, with no network and no Python. Chart Data Collection is set to 30 s so every pass records price rows and a portfolio snapshot. The 120 s window is measured like the idle window, giving refresh_passes, refresh_cpu_s, refresh_energy_j, refresh_wakeups, refresh_disk_written_mb, refresh_footprint_mb_median and refresh_heap_growth_mb. The app takes this workload only in an acceptance run with live providers off. Refresh launches come after the others because a refresh changes the stored data the next launch starts from. They take about 3.5 minutes each.

A soak run is the same thing with one long window:

bash Scripts/perf/benchmark.sh --label soak --runs 1 --window 1800

Two commits against each other: compare.sh

bash Scripts/perf/compare.sh experimental HEAD --label my-change

It exports and builds each commit (never the uncommitted working tree), then measures them in turns (before, after, after, before). It prints the table a pull request carries: for every figure the median and range of each side, the change, and a verdict from a rank-sum permutation test over the launches.

p-value Verdict
Below 0.01 "lower" or "higher"
0.01 to 0.05 "possibly lower" or "possibly higher". With fifteen rows, the same commit measured against itself reaches this on some row often enough that such a row needs a repeat before it counts.
Anything else "no measurable change"

The default is six launches a side and takes about 35 minutes. Four a side can reach "possibly" at best, and with fewer nothing can be told apart. --refresh adds the refresh rows and takes about 75 minutes. Comparing a commit with itself shows the noise of the method. Do not build, run tests or use the Mac heavily while a benchmark runs.

What the helper holds: helper_layers.py

It starts the helper's interpreter with one more layer of imports each time (the interpreter alone, the standard library modules, requests, pandas, yfinance) and prints the memory each holds once the imports are done, with the CPU and time that took. Nothing is fetched. It can also compare against two tiny compiled "floor" programs (native_floor.swift, native_floor.rs) that write one line and wait, to show where a compiled helper would start from.

What these do not measure

  • Whole-system battery drain. app_power_mw covers only CPU work billed to the process, not the display, the graphics processor or the network.
  • How smooth the interface is (dropped frames, how long a click takes). Instruments does this.
  • A quote refresh over the network, or the helper's lifetime between refreshes. Acceptance mode never starts the helper, so only measure_performance.sh against the real app sees them.

What 3.8.0 changed, as measured

EXPERIMENTAL_LOG.md records every change with its own comparison. The memory and history changes were also measured together against the baseline, 3.7.0, when they were first promoted to testing (6 launches a side, in turns, on 2026-11-13). The refresh changes that followed were measured one by one, not together against the baseline.

Metric Baseline After Change
Idle memory (physical footprint) 119.9 MB 95.8 MB -24.2 MB, -20.1%
Idle memory the app holds allocated 63.8 MB 54.5 MB -9.3 MB, -14.6%
Peak memory, launch and history load 285.1 MB 244.9 MB -40.1 MB, -14.1%
Launch to history loaded 1.20 s 0.63 s -0.57 s, -47.3%
CPU from launch to the idle window 2.64 s 1.88 s -0.76 s, -28.8%
CPU energy from launch to the idle window 7.85 J 6.07 J -1.78 J, -22.6%

Idle CPU, wake-ups, idle CPU power, disk writes, launch to first window and the three Python helper rows did not change measurably.

The individual changes, in the log's words:

  • Release builds no longer carry test-coverage counters; the executable is 6.7 MB smaller.
  • Stored portfolio history is read in batches, and at launch away from the main thread.
  • Each portfolio snapshot's positions are kept in a sorted array instead of a dictionary, and the price history held in memory is kept in arrays sized to their points.
  • The chart of the portfolio's value reads stored history without each snapshot's positions.
  • The popover charts no longer draw their line doubling back either side of a gap in time. This is a bug fix, not an optimisation, and the benchmark does not run its code.
  • The idle Python helper quits after 90 seconds, controlled by Settings → Advanced → Memory → Quit Python Helper When Idle. It is on by default since the owner's decision on 2026-11-13; turned off, the helper is kept for 15 minutes. What it saves on real data is expected, not measured; the log notes that it trades memory for CPU.
  • Roll Digits When Figures Change lets you turn off the rolling digits. With it off, the system's cache of drawn digits held 0.4 MB against 9.4 to 9.9 MB with it on, in two launches each way. The standard benchmark was not run for this change.

The refresh path, which the benchmark could not run until its refresh workload was added, came next, after a read-only review whose findings the owner chose from:

  • Each refresh's quotes are applied together, so the main window redraws once per refresh instead of once per symbol. On the refresh workload it halved the CPU and CPU energy of the refresh passes (3.4 s against 6.8 s of CPU over four refreshes) and raised their CPU wake-ups by 32%, which come with the rolling digits now getting to animate.
  • The Python helper reads and writes its quote cache once per refresh rather than once per symbol: for 22 symbols, 2 reads of the cache file against 66 and 2 forced writes to disk against 44.
  • A symbol's price history is read only for the time window asked for: the day reads at launch took 11 to 14 ms against about 410 ms.
  • A history cache file is not rewritten when its value has not changed.
  • The portfolio popover releases its content when it closes, so a closed popover is no longer redrawn at every refresh. In a trial copy, 16 redraws over four refreshes became none.
  • The session's portfolio snapshots no longer carry a price for every position, which nothing read: about 2.3 MB less over a long session with 11 positions, worked out from the sizes of the data.

The log also lists what was measured and not pursued (precompiled bytecode for the helper's scripts, thinning only the newly aged part of each price series, combining a refresh's Core Data transactions) and why. See its "Tried and rejected" section.

Should the fetch leave Python?

The log's Rust evaluation (2026-11-12) concluded that no component should move to Rust. The one large saving is the Python helper, and it comes from leaving Python, not from arriving at Rust: a compiled helper starts from 1 to 3 MB in either language, against 70.6 MB for the Python helper after its imports (pandas accounts for 36.8 MB and yfinance for 13.4 MB). Nothing inside the app was found that Rust would make faster or smaller. Whether the market-data fetch should leave Python at all is a larger decision that the log leaves to the repository owner. The answer recorded there is to keep Python and use the idle-quit switch, and to move the fetch to Swift only after a supervised trial against Yahoo.

How the experimental branch was run

The experimental branch carried this work. Its rules ("How this branch works" in the log) are useful for any future overhaul:

  • One optimisation is one branch, one pull request and one squash commit, so it can be read and reverted alone. A merged change is undone with git revert through a pull request.
  • Every pull request carries its own before/after table from compare.sh, measured for that pull request, and names the rows it is meant to move. A row that moves without having been named is repeated before it counts, whatever its p value. Nothing else runs on the Mac during a comparison.
  • Merge bar: the app builds cleanly, there are no new test failures, the affected behaviour still works, the benchmark record is complete and there is no known regression. A change that trades one metric for another stays open for a decision, and a performance change with no measurable benefit is not merged.
  • CI does not run for experimental, so every check is run locally: test, checks, python-tests, build-release and the tooling tests. See Development.
  • Checkpoint tags are named experimental-checkpoint-<date>-<name>. The release workflow ignores them.
  • Promotion to testing is made only at the owner's word, from a temporary branch with a merge commit, followed by merging testing back into experimental. See Branches and Releases.
  • The log also records breaks in the measuring environment (for example an operating-system update, or the screen being locked), and figures from either side of a break are not compared.

Since 2026-11-17 the owner has considered that overhaul finished, and experimental is used only for major changes or temporary testing. That is why the Experimental update channel may go quiet for long periods; see Updates and Channels.

Benchmark output is written to build/bench/results/, which is git-ignored, so it stays on the machine that ran it.

Clone this wiki locally