-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Description
Z3 Performance Improvement Plan
This issue outlines a comprehensive plan for improving performance in the Z3 theorem prover based on deep research into the codebase.
Current Performance Infrastructure
Testing & Benchmarking
- Regression Testing: Uses
z3testrepository with SMT2 benchmarks - CI/CD: Azure Pipelines with multiple build configurations
- Built-in Profiling: Comprehensive timing (
src/util/timeit.h,src/util/stopwatch.h) and statistics framework (src/util/statistics.h) - Command-line Tools:
z3 -st,z3 -(redacted)z3 -(redacted) for performance monitoring
Build Configuration
# Optimized build
python scripts/mk_make.py && cd build && make -j8
cmake -DCMAKE_BUILD_TYPE=Release -DZ3_LINK_TIME_OPTIMIZATION=ONBenchmarking Commands
# Clone and run regression tests
git clone https://github.com/z3prover/z3test
python z3test/scripts/test_benchmarks.py build/z3 z3test/regressions/smt2Performance Characteristics
Z3 is primarily:
- CPU-bound: Complex algorithmic computations
- Memory-intensive: Dynamic data structures (clauses, watches, assignments)
- Search-heavy: Backtracking with heuristic guidance
Performance Improvement Opportunities
Round 1: Memory & Micro-optimizations (5-15% improvement)
Priority Targets:
-
Small Object Allocator (
src/util/small_object_allocator.h)- Current: 8KB chunks, 256-byte objects
- Opportunity: Pool-based allocation for specific object sizes
- Location: `small_object_allocator.(redacted)
-
Clause Management (
src/sat/sat_clause.cpp)- Dynamic clause creation/deletion overhead
- Memory defragmentation during GC
- Location: `sat_clause.(redacted)
-
Hash Table Optimization (
src/util/hashtable.h)- Better load factor management
- Cache-friendly layouts
- Location: `hashtable.(redacted)
Commands for Round 1:
# Profile memory allocation
valgrind --tool=massif --stacks=yes ./z3 benchmark.smt2
# CPU profiling
perf record -g ./z3 benchmark.smt2Round 2: Algorithmic Enhancements (15-30% improvement)
Priority Targets:
-
SAT Solver Core (
src/sat/sat_solver.cpp)- VSIDS heuristic optimization
- Conflict analysis improvements
- Watched literals scheme enhancements
- Location: `sat_solver.(redacted) sat_watched.(redacted)
-
SIMD Vectorization
- Bit-vector operations (
src/util/bit_vector.h) - Parallel clause evaluation
- Location: `bit_vector.(redacted)
- Bit-vector operations (
-
Theory Solver Optimizations
- Linear arithmetic (
src/math/lp/) - Simplex algorithm - Array theory extensional reasoning
- Location:
lp/*.cpp,src/smt/theory_array.cpp
- Linear arithmetic (
Commands for Round 2:
# Theory-specific benchmarks
./z3 -st -(redacted) theory_specific.smt2
# Detailed SAT solver stats
./z3 -st sat.gc.initial=5000 benchmark.smt2Round 3: Architectural Changes (30%+ improvement)
Priority Targets:
-
Parallel Algorithm Improvements
- Better thread coordination in parallel SAT solving
- Lock-free data structures for shared state
- Location:
src/sat/sat_parallel.cpp
-
Data Structure Layout Optimization
- Cache-friendly struct packing
- Memory prefetching in critical loops
- Location: Core SAT solver data structures
-
Advanced Heuristics
- Machine learning-guided variable ordering
- Improved learned clause management
- Location:
src/sat/sat_*.cppheuristic files
Performance Tuning Parameters
SAT Solver Key Parameters:
# Aggressive GC
sat.gc.initial=10000
# Faster restarts
sat.restart.initial=100
# Memory limit
sat.max_memory=4096
# Parallel solving
sat.threads=8Bottleneck Analysis
Hot Functions (typical profiles):
(redacted))- Unit propagation(redacted))- Conflict analysis(redacted))- Relevancy reasoning- Memory allocation/deallocation functions
Data Structure Hotspots:
- Watch lists indexing
- Clause storage locality
- Hash table collisions
- Activity heap operations
Environment Setup
Required Tools:
# Profiling tools
apt install valgrind perf linux-tools-common
# Build dependencies
cmake, make, g++/clang++
# Benchmarking
git clone https://github.com/z3prover/z3testPerformance Testing Workflow:
- Build optimized version:
python scripts/mk_make.py && cd build && make -j8 - Run baseline benchmarks:
python z3test/scripts/test_benchmarks.py build/z3 z3test/regressions/smt2 - Profile with
perf/valgrindon specific bottlenecks - Implement optimization
- Re-benchmark and compare results
Success Metrics
- Throughput: Problems solved per second on benchmark suite
- Memory: Peak memory usage reduction
- Latency: Time to first solution on representative problems
- Scalability: Performance on large instances
Next Steps
- Select specific optimization target from Round 1
- Create performance testing environment
- Take baseline measurements
- Implement optimization
- Measure improvement and create pull request
> AI-generated content by Daily Perf Improver may contain mistakes.
Generated by Agentic Workflow Run