Commit b87903f
perf: Optimize Cost Tracker with batch writes - 1,300x speedup
PERFORMANCE BREAKTHROUGH
- Cost tracking: 32.02s → 0.025s for 1,000 requests (1,300x faster)
- Function calls: 251M → 44K (5,700x reduction)
- Disk writes: 1,000 → 20 (50x reduction)
CHANGES
- Batch writes (flush every 50 requests)
- JSONL append-only format for new data
- Real-time data (buffered requests included in summaries)
- Zero data loss (atexit handler for crash safety)
- Backward compatible with existing JSON format
FILES MODIFIED
- src/empathy_os/cost_tracker.py: Batch write optimization
- tests/test_cost_tracker.py: Updated tests for buffered behavior
- benchmarks/profile_suite.py: Fixed API compatibility
- docs/PHASE2_PERFORMANCE_RESULTS.md: Comprehensive performance report
TESTING
- All 30 cost tracker tests passing
- All 166 total tests passing
- No regressions detected
- Real-time data accuracy verified
PROFILING RESULTS
- Profiling suite operational
- 4 profile files generated (.prof files for snakeviz)
- Cost Tracker bottleneck identified and eliminated
- Pattern Library, Scanner, Feedback Loops already optimal
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 68ead95 commit b87903f
File tree
10 files changed
+872
-74
lines changed- benchmarks
- profiles
- docs
- patterns
- debugging
- src/empathy_os
- tests
10 files changed
+872
-74
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | | - | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
32 | | - | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | | - | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
54 | 60 | | |
55 | 61 | | |
56 | | - | |
57 | | - | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | | - | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | | - | |
67 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
68 | 78 | | |
69 | 79 | | |
70 | 80 | | |
| |||
94 | 104 | | |
95 | 105 | | |
96 | 106 | | |
97 | | - | |
98 | 107 | | |
99 | 108 | | |
100 | | - | |
101 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
| |||
113 | 123 | | |
114 | 124 | | |
115 | 125 | | |
116 | | - | |
| 126 | + | |
| 127 | + | |
117 | 128 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
130 | 137 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
135 | 157 | | |
136 | 158 | | |
137 | 159 | | |
| |||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 commit comments