Performance Boundaries
Cache Decision
Reuse or Rebuild
A cache boundary chooses between reusing known work and rebuilding fresh output. Modeling the decision keeps the cost tradeoff visible.
Program
Play the script to choose the cache state and see the planned action.
cache_decision_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
cache_hit=1
if [[ "$cache_hit" -eq 1 ]]; then
action="reuse"
cost=1
else
action="rebuild"
cost=5
fi
echo "$action cost=$cost"
#!/usr/bin/env bash
cache_hit=0
if [[ "$cache_hit" -eq 1 ]]; then
action="reuse"
cost=1
else
action="rebuild"
cost=5
fi
echo "$action cost=$cost"
cache_hit ← 1
3cache_hit=14if [[ "$cache_hit" -eq 1 ]]; thenvalues this step1cache_hitif [[ "$cache_hit" -eq 1 ]]; then
3cache_hit=14if [[ "$cache_hit" -eq 1 ]]; then5 action="reuse"values this step1cache_hitaction ← reuse
4if [[ "$cache_hit" -eq 1 ]]; then5 action="reuse"6 cost=1values this stepreuseactioncost ← 1
5 action="reuse"6 cost=17elsevalues this step1costecho "$action cost=$cost"
10fi11echo "$action cost=$cost"outputreuse cost=1values this stepreuseaction1cost
cache_hit ← 0
3cache_hit=04if [[ "$cache_hit" -eq 1 ]]; thenvalues this step0cache_hitif [[ "$cache_hit" -eq 1 ]]; then
3cache_hit=04if [[ "$cache_hit" -eq 1 ]]; then5 action="reuse"values this step0cache_hitaction ← rebuild
7else8 action="rebuild"9 cost=5values this steprebuildactioncost ← 5
8 action="rebuild"9 cost=510fivalues this step5costecho "$action cost=$cost"
10fi11echo "$action cost=$cost"outputrebuild cost=5values this steprebuildaction5cost
cache hit
A cache hit means previous work can be reused.
cost model
A small cost model makes the tradeoff visible without benchmarking.
rebuild path
The rebuild path is more expensive but refreshes the output.