Skip to content

Commit 1277374

Browse files
iduartgomezclaudesanity
authored
perf(transport): add fast_channel for high-performance packet routing (#2263)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Ian Clarke <sanity@users.noreply.github.com>
1 parent 0d24d0d commit 1277374

File tree

13 files changed

+880
-1775
lines changed

13 files changed

+880
-1775
lines changed

.github/workflows/benchmarks.yml

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,30 @@ jobs:
7575
echo "⚠️ No baseline found - this run will establish the baseline" >> $GITHUB_STEP_SUMMARY
7676
fi
7777
78-
# Run Level 0 benchmarks (pure logic, deterministic)
79-
- name: Run Level 0 Benchmarks (Pure Logic)
80-
id: bench_level0
78+
# Run Transport Layer Benchmarks (actual code with mock I/O)
79+
- name: Run Transport Layer Benchmarks
80+
id: bench_transport
8181
run: |
82-
echo "## Level 0: Pure Logic Benchmarks" >> $GITHUB_STEP_SUMMARY
82+
echo "## Transport Layer Performance" >> $GITHUB_STEP_SUMMARY
8383
echo "" >> $GITHUB_STEP_SUMMARY
84-
echo "These benchmarks measure pure computation without I/O:" >> $GITHUB_STEP_SUMMARY
85-
echo "- AES-GCM encryption/decryption" >> $GITHUB_STEP_SUMMARY
86-
echo "- Serialization" >> $GITHUB_STEP_SUMMARY
87-
echo "- Nonce generation" >> $GITHUB_STEP_SUMMARY
84+
echo "These benchmarks test the actual transport code with mock sockets:" >> $GITHUB_STEP_SUMMARY
85+
echo "- **Message throughput**: Full pipeline (serialize → encrypt → channel → decrypt)" >> $GITHUB_STEP_SUMMARY
86+
echo "- **fast_channel**: Crossbeam-based channel performance vs tokio::sync::mpsc" >> $GITHUB_STEP_SUMMARY
87+
echo "- **Connection establishment**: Full handshake timing" >> $GITHUB_STEP_SUMMARY
8888
echo "" >> $GITHUB_STEP_SUMMARY
8989
90-
# Run benchmarks and capture output
91-
cargo bench --bench transport_perf -- level0 2>&1 | tee bench_output.txt
90+
# Run transport benchmarks (requires bench feature)
91+
cargo bench --bench transport_perf --features bench -- transport 2>&1 | tee bench_output.txt
9292
93-
# Parse for regressions (criterion outputs "regressed" for performance decreases)
9493
if grep -q "regressed" bench_output.txt; then
9594
echo "regression_detected=true" >> $GITHUB_OUTPUT
96-
echo "### ⚠️ Performance Regressions Detected" >> $GITHUB_STEP_SUMMARY
97-
echo "" >> $GITHUB_STEP_SUMMARY
95+
echo "### ⚠️ Transport Regressions Detected" >> $GITHUB_STEP_SUMMARY
9896
echo '```' >> $GITHUB_STEP_SUMMARY
99-
grep -A2 "regressed" bench_output.txt >> $GITHUB_STEP_SUMMARY || true
97+
grep -B5 "regressed" bench_output.txt | tail -30 >> $GITHUB_STEP_SUMMARY || true
10098
echo '```' >> $GITHUB_STEP_SUMMARY
10199
else
102100
echo "regression_detected=false" >> $GITHUB_OUTPUT
103-
echo "### ✅ No Regressions Detected" >> $GITHUB_STEP_SUMMARY
101+
echo "### ✅ No Transport Regressions" >> $GITHUB_STEP_SUMMARY
104102
fi
105103
106104
# Also capture any improvements
@@ -145,25 +143,55 @@ jobs:
145143

146144
# Post comment on PR with regression summary
147145
- name: Comment on PR
148-
if: github.event_name == 'pull_request' && steps.bench_level0.outputs.regression_detected == 'true'
146+
if: github.event_name == 'pull_request' && steps.bench_transport.outputs.regression_detected == 'true'
149147
uses: actions/github-script@v7
150148
with:
151149
script: |
152150
const fs = require('fs');
153151
const output = fs.readFileSync('bench_output.txt', 'utf8');
154-
155-
// Extract regression lines
156-
const regressions = output.split('\n')
157-
.filter(line => line.includes('regressed') || line.includes('change:'))
158-
.slice(0, 20) // Limit to 20 lines
159-
.join('\n');
152+
const lines = output.split('\n');
153+
154+
// Criterion outputs benchmark results like:
155+
// level0/crypto/encrypt time: [1.234 µs 1.250 µs 1.270 µs]
156+
// change: [+1.23% +2.34% +3.45%] (p = 0.00 < 0.01)
157+
// Performance has regressed.
158+
//
159+
// We need to capture the benchmark name (line with "time:") along with regression info
160+
161+
let regressions = [];
162+
let currentBenchmark = null;
163+
164+
for (let i = 0; i < lines.length; i++) {
165+
const line = lines[i];
166+
167+
// Capture benchmark name (lines containing "time:" have the benchmark name at the start)
168+
if (line.includes('time:')) {
169+
currentBenchmark = line.split('time:')[0].trim();
170+
}
171+
172+
// When we find a regression, include the benchmark name
173+
if (line.includes('Performance has regressed')) {
174+
// Look back for the change line
175+
const changeLine = i > 0 ? lines[i - 1] : '';
176+
const changeMatch = changeLine.match(/change:\s*\[([\d.+%-]+)\s+([\d.+%-]+)\s+([\d.+%-]+)\]/);
177+
const changeStr = changeMatch ? changeMatch[2] : 'unknown';
178+
179+
if (currentBenchmark) {
180+
regressions.push(`• ${currentBenchmark}: ${changeStr}`);
181+
}
182+
}
183+
}
184+
185+
const regressionsText = regressions.length > 0
186+
? regressions.slice(0, 15).join('\n')
187+
: 'See workflow summary for details';
160188
161189
const body = `## ⚠️ Performance Benchmark Regressions Detected
162190
163191
The following benchmarks show performance regression compared to the baseline:
164192
165193
\`\`\`
166-
${regressions || 'See workflow summary for details'}
194+
${regressionsText}
167195
\`\`\`
168196
169197
> **Note:** This is informational only and does not block the PR. Please review if the regression is expected or needs investigation.

crates/core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ regex = "1"
113113
[[bench]]
114114
name = "transport_perf"
115115
harness = false
116+
required-features = ["bench"]
116117

117118
[features]
118119
default = ["redb", "trace", "websocket"]
@@ -123,3 +124,4 @@ websocket = ["axum/ws"]
123124
testing = ["freenet-stdlib/testing"]
124125
console-subscriber = ["dep:console-subscriber"]
125126
test-network = ["dep:freenet-test-network"]
127+
bench = [] # Exposes internal test infrastructure for benchmarking

0 commit comments

Comments
 (0)