Skip to content

Commit 3efa0d8

Browse files
sidmohan0claude
andcommitted
fix(performance): eliminate memory debugging overhead from benchmarks
The 3-4x performance regression was caused by memory optimization environment variables (PYTHONMALLOC=debug, single-threading) that prevent segfaults but severely impact benchmark performance. Changes: - Remove CI=true/GITHUB_ACTIONS=true from benchmark workflows to avoid memory debugging - Set optimal performance environment for benchmarks (4 threads vs 1) - Use direct pytest for benchmarks instead of run_tests.py wrapper - Keep memory optimizations only for regular tests that need segfault protection - Maintain consistent text size (100 repetitions) across all environments This should restore benchmark performance to expected levels while maintaining segfault protection for regular test runs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a886334 commit 3efa0d8

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

.github/workflows/benchmark.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ jobs:
3939
4040
- name: Run benchmarks and save baseline
4141
env:
42-
CI: true
43-
GITHUB_ACTIONS: true
42+
# DO NOT set CI=true or GITHUB_ACTIONS=true here to avoid memory optimization slowdowns
43+
# Set optimal performance environment for benchmarks
44+
OMP_NUM_THREADS: 4
45+
MKL_NUM_THREADS: 4
46+
OPENBLAS_NUM_THREADS: 4
4447
run: |
45-
# Run benchmarks with segfault protection and save results
46-
echo "Running benchmarks with memory optimizations..."
48+
# Run benchmarks with optimal performance settings (no memory debugging)
49+
echo "Running benchmarks with performance-optimized settings..."
4750
python -m pytest tests/benchmark_text_service.py -v --benchmark-autosave --benchmark-json=benchmark-results.json --tb=short
4851
4952
- name: Check for performance regression

.github/workflows/beta-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ jobs:
126126
echo "Running integration tests..."
127127
python run_tests.py -m integration --no-header
128128
129-
# Run benchmark tests with segfault protection
130-
echo "Running benchmark tests with safeguards..."
131-
python run_tests.py tests/benchmark_text_service.py --no-header
129+
# Run benchmark tests with optimal performance (no memory debugging)
130+
echo "Running benchmark tests with performance optimizations..."
131+
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 python -m pytest tests/benchmark_text_service.py -v --no-header
132132
133133
- name: Build package
134134
run: |

tests/benchmark_text_service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ def sample_text_10kb():
2626
# Check if running in CI environment
2727
import os
2828

29+
# For performance benchmarks, always use consistent moderate size for stable results
30+
# regardless of environment to avoid performance variance from text size differences
2931
if os.environ.get("CI") or os.environ.get("GITHUB_ACTIONS"):
3032
# Use moderate sample in CI for stable benchmarks (not too small to avoid variance)
3133
repetitions = 100 # Increased from 50 for more stable results
3234
else:
33-
# Use full size for local development
34-
repetitions = 10000 // len(base_text) + 1
35+
# Use moderate size for local development benchmarks too for consistency
36+
repetitions = 100 # Keep consistent with CI for fair comparison
3537

3638
return base_text * repetitions
3739

0 commit comments

Comments
 (0)