mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 13:29:11 +00:00 
			
		
		
		
	Don't reset the cache between applications of replace
tactic/lia2card shows a huge slowdown because the same replace function is called on thousands of assertions. Each time the cache gets reset with thousands of entries - they are all the same. So don't reset the cache just because... Instead reset the cache if m_refs grows large.
This commit is contained in:
		
							parent
							
								
									99b606b861
								
							
						
					
					
						commit
						477e9625ef
					
				
					 1 changed files with 11 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -27,6 +27,7 @@ void expr_safe_replace::insert(expr* src, expr* dst) {
 | 
			
		|||
    SASSERT(src->get_sort() == dst->get_sort());
 | 
			
		||||
    m_src.push_back(src);
 | 
			
		||||
    m_dst.push_back(dst);
 | 
			
		||||
    m_cache.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void expr_safe_replace::operator()(expr_ref_vector& es) {
 | 
			
		||||
| 
						 | 
				
			
			@ -45,13 +46,15 @@ void expr_safe_replace::operator()(expr* e, expr_ref& res) {
 | 
			
		|||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (unsigned i = 0, e = m_src.size(); i < e; ++i) {
 | 
			
		||||
    if (m_cache.empty()) {
 | 
			
		||||
        for (unsigned i = 0, e = m_src.size(); i < e; ++i) 
 | 
			
		||||
            m_cache.emplace(m_src.get(i), m_dst.get(i));
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    m_todo.push_back(e);
 | 
			
		||||
    expr* a, *b;
 | 
			
		||||
 | 
			
		||||
    m_refs.push_back(e);
 | 
			
		||||
    while (!m_todo.empty()) {
 | 
			
		||||
        a = m_todo.back();
 | 
			
		||||
        auto &cached = m_cache[a];
 | 
			
		||||
| 
						 | 
				
			
			@ -166,10 +169,12 @@ void expr_safe_replace::operator()(expr* e, expr_ref& res) {
 | 
			
		|||
        }        
 | 
			
		||||
    }
 | 
			
		||||
    res = m_cache.at(e);
 | 
			
		||||
    if (m_refs.size() > 1 << 20) {
 | 
			
		||||
        m_cache.clear();
 | 
			
		||||
        m_refs.reset();
 | 
			
		||||
    }
 | 
			
		||||
    m_todo.reset();
 | 
			
		||||
    m_args.reset();
 | 
			
		||||
    m_refs.reset();    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void expr_safe_replace::reset() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue