perf(kernel,library/module): enable expr caching when deserializing .olean files

This commit is contained in:
Leonardo de Moura 2016-12-16 18:33:46 -08:00
parent 6b15f6cef9
commit 5572d7f3ec
5 changed files with 16 additions and 7 deletions

View file

@ -348,13 +348,11 @@ bool enable_expr_caching(bool f) {
DEBUG_CODE(bool r1 =) enable_level_caching(f);
bool r2 = g_expr_cache_enabled;
lean_assert(r1 == r2);
expr_cache new_cache;
get_expr_cache().swap(new_cache);
cache(mk_Prop());
cache(mk_Type());
if (f) {
clear_abstract_cache();
clear_instantiate_cache();
cache(mk_Prop());
cache(mk_Type());
}
g_expr_cache_enabled = f;
return r2;
@ -362,7 +360,13 @@ bool enable_expr_caching(bool f) {
bool is_cached(expr const & e) {
return get_expr_cache().find(e) != get_expr_cache().end();
}
void flush_expr_cache() {
flush_level_cache();
expr_cache new_cache;
get_expr_cache().swap(new_cache);
clear_abstract_cache();
clear_instantiate_cache();
}
expr mk_var(unsigned idx, tag g) {
return cache(expr(new (get_var_allocator().allocate()) expr_var(idx, g)));
}

View file

@ -503,6 +503,7 @@ struct scoped_expr_caching {
};
/** \brief Return true iff \c e is in the cache */
bool is_cached(expr const & e);
void flush_expr_cache();
// =======================================
// =======================================

View file

@ -267,12 +267,14 @@ MK_THREAD_LOCAL_GET_DEF(level_cache, get_level_cache);
bool enable_level_caching(bool f) {
bool r = g_level_cache_enabled;
g_level_cache_enabled = f;
level_cache new_cache;
get_level_cache().swap(new_cache);
get_level_cache().insert(mk_level_zero());
get_level_cache().insert(mk_level_one());
return r;
}
void flush_level_cache() {
level_cache new_cache;
get_level_cache().swap(new_cache);
}
level cache(level const & e) {
if (g_level_cache_enabled) {
level_cache & cache = get_level_cache();

View file

@ -82,6 +82,7 @@ inline optional<level> some_level(level && e) { return optional<level>(std::forw
bool enable_level_caching(bool f);
level cache(level const & l);
bool is_cached(level const & l);
void flush_level_cache();
level const & mk_level_zero();
level const & mk_level_one();

View file

@ -439,6 +439,7 @@ void import_module(std::vector<char> const & olean_code, std::string const & fil
// TODO(gabriel): update extension
std::string s(olean_code.data(), olean_code.size());
std::istringstream in(s, std::ios_base::binary);
scoped_expr_caching enable_caching(true);
deserializer d(in, optional<std::string>(file_name));
unsigned obj_counter = 0;
while (true) {