Skip to content

Fix loop inefficiencies: double test run, sleep, config loading #144

@federiconeri

Description

@federiconeri

Problem

Several small inefficiencies in feature-loop.sh.tmpl add up:

1. Double baseline test run (lines 620-628)

Tests run twice when any fail: once to check exit code, again to capture failures.

if (cd "$APP_DIR" && eval "$TEST_COMMAND" 2>&1) > /dev/null 2>&1; then
    : > "$BASELINE_FAILURES_FILE"
else
    (cd "$APP_DIR" && eval "$TEST_COMMAND" 2>&1) | normalize_test_failures > ...
fi

Fix: Run once, capture output, check both exit code and parse failures:

TEST_OUTPUT=$( (cd "$APP_DIR" && eval "$TEST_COMMAND") 2>&1) || true
TEST_EXIT=$?
if [ $TEST_EXIT -eq 0 ]; then
    : > "$BASELINE_FAILURES_FILE"
else
    echo "$TEST_OUTPUT" | normalize_test_failures > "$BASELINE_FAILURES_FILE"
fi

2. Unconditional sleep 2 (line 736)

2-second sleep after every implementation iteration. Over 6 iterations = 12 wasted seconds.

Fix: Remove the sleep entirely, or only sleep on failure (to throttle retries).

3. Config loaded via 9 separate node -e calls (lines 18-52)

Each reads one value from ralph.config.cjs, spawning a separate Node process.

Fix: Single node call outputting all values:

eval $(node -e "
  const c = require('$CONFIG_PATH');
  console.log('RALPH_ROOT=' + (c.paths?.root || '.ralph'));
  console.log('SPEC_DIR=' + (c.paths?.specs || '.ralph/specs'));
  // ... etc
" 2>/dev/null) || { RALPH_ROOT=".ralph"; SPEC_DIR=".ralph/specs"; ... }

4. Git diff computed 4 times identically (lines 707, 740, 835, 1001)

Same baseline-vs-HEAD diff pattern repeated. Could be a cached function.

Files

  • src/templates/scripts/feature-loop.sh.tmpl

Estimated Savings

  • ~10-30s from fixing double test run
  • ~12s from removing sleep
  • ~2-3s from consolidating config loading
  • ~30s total

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Lower priorityenhancementEnhancement to existing featureperformancePerformance optimization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions