Skip to content

Daily Perf Improver - Research and Plan #7883

@github-actions

Description

@github-actions

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 z3test repository 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=ON

Benchmarking Commands

# Clone and run regression tests
git clone https://github.com/z3prover/z3test
python z3test/scripts/test_benchmarks.py build/z3 z3test/regressions/smt2

Performance 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:

  1. 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)
  2. Clause Management (src/sat/sat_clause.cpp)

    • Dynamic clause creation/deletion overhead
    • Memory defragmentation during GC
    • Location: `sat_clause.(redacted)
  3. 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.smt2

Round 2: Algorithmic Enhancements (15-30% improvement)

Priority Targets:

  1. 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)
  2. SIMD Vectorization

    • Bit-vector operations (src/util/bit_vector.h)
    • Parallel clause evaluation
    • Location: `bit_vector.(redacted)
  3. Theory Solver Optimizations

    • Linear arithmetic (src/math/lp/) - Simplex algorithm
    • Array theory extensional reasoning
    • Location: lp/*.cpp, src/smt/theory_array.cpp

Commands for Round 2:

# Theory-specific benchmarks
./z3 -st -(redacted) theory_specific.smt2
# Detailed SAT solver stats
./z3 -st sat.gc.initial=5000 benchmark.smt2

Round 3: Architectural Changes (30%+ improvement)

Priority Targets:

  1. Parallel Algorithm Improvements

    • Better thread coordination in parallel SAT solving
    • Lock-free data structures for shared state
    • Location: src/sat/sat_parallel.cpp
  2. Data Structure Layout Optimization

    • Cache-friendly struct packing
    • Memory prefetching in critical loops
    • Location: Core SAT solver data structures
  3. Advanced Heuristics

    • Machine learning-guided variable ordering
    • Improved learned clause management
    • Location: src/sat/sat_*.cpp heuristic 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=8

Bottleneck 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/z3test

Performance Testing Workflow:

  1. Build optimized version: python scripts/mk_make.py && cd build && make -j8
  2. Run baseline benchmarks: python z3test/scripts/test_benchmarks.py build/z3 z3test/regressions/smt2
  3. Profile with perf/valgrind on specific bottlenecks
  4. Implement optimization
  5. 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

  1. Select specific optimization target from Round 1
  2. Create performance testing environment
  3. Take baseline measurements
  4. Implement optimization
  5. Measure improvement and create pull request

> AI-generated content by Daily Perf Improver may contain mistakes.

Generated by Agentic Workflow Run

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions