lean4-htt/src/kernel
Leonardo de Moura 04dfd55f94 perf(kernel/expr): fix hash consing performance problem
The kernel support opportunistic hash consing.
At commit e63c79c81e we have enabled this feature during
tactic execution, and fixed performance problems in the Certigrad
project (by @dselsam).
However, this change produced unexpected performance problems in
other Lean files (example: @JasonGross example at issue #1646 was 10x
slower after the commit above).
After analyzing the performance logs, I conjecture the hash_consing
may produce a substantial performance overhead if the following property
doesn't hold.

- Let `cache` be the hash_consing cache, then for each `e` in `cache`,
all children of `e` are also in the `cache`.

If the property above is not true, we may have problem whenever
we add an expression `t` containing multiple copies of a big term `T`.
For example, support we insert `f T_1 T_2`, where `T_1` and `T_2` are
structurally equal but are not pointer equal. Then, if we try to insert
`f T_2 T_1`, we will have to compare the huge terms twice, and the
comparison will be proportional to the size of `T_i`.

This commit tries to address this performance problem by enforcing
the property above. This is not a perfect solution since we may keep
trying to create terms using big terms created before hash_consing
has been enabled. After this commit, the example at issue #1646
is only 1.4x slower. It didn't impact the standard library
compilation (memory nor time).

I'm using this commit is a temporary workaround. We should probably
remove the hash_consing support from the kernel, and implement it
in key places. For example, for Certigrad, we can control memory
consumption by using hash_consing only during `simp`,
`instantiate_mvars` and `elaborator` finalization procedure.

@gebner @kha Any ideas/suggestions for this hash_consing issue?
2017-06-23 12:41:35 -07:00
..
inductive feat(kernel/inductive,library/inductive_compiler): do not enforce positivity rule on meta inductives 2017-05-14 19:17:28 -07:00
quotient chore(kernel/quotient/quotient): update comments 2017-03-07 14:11:51 -08:00
abstract.cpp feat(kernel): add compilation flags for disabling has_local optimization and abstraction cache 2017-02-21 19:46:31 -08:00
abstract.h fix(frontends/lean/structure_cmd): remove evil Pi overload that accidentally abstracted constants in structure decls 2017-04-26 14:22:36 -07:00
abstract_type_context.cpp fix(frontends/lean/pp): qualify constant shadowed by local 2017-03-31 09:40:49 -07:00
abstract_type_context.h fix(frontends/lean/pp): qualify constant shadowed by local 2017-03-31 09:40:49 -07:00
cache_stack.h perf(kernel/for_each_fn): use cache stack trick at for_each_fn 2014-07-23 19:32:11 -07:00
CMakeLists.txt refactor(*): reduce exception context info from expr to pos_info 2017-02-17 13:45:57 +01:00
declaration.cpp refactor(*): task<T>, log_tree, cancellation_token 2017-03-23 08:57:52 +01:00
declaration.h refactor(*): task<T>, log_tree, cancellation_token 2017-03-23 08:57:52 +01:00
environment.cpp refactor(*): task<T>, log_tree, cancellation_token 2017-03-23 08:57:52 +01:00
environment.h chore(kernel/environment): rename method 2017-05-15 14:18:16 -07:00
equiv_manager.cpp feat(kernel): add let-expressions to the kernel 2016-02-29 16:40:17 -08:00
equiv_manager.h feat(kernel/equiv_manager): use expr_struct_map in the equiv_manager 2016-07-07 07:39:25 -07:00
error_msgs.cpp fix(frontends/lean/elaborator, kernel/error_msgs): (re-)activate distinguishing_pp_options 2017-01-30 11:54:00 -08:00
error_msgs.h fix(frontends/lean/elaborator, kernel/error_msgs): (re-)activate distinguishing_pp_options 2017-01-30 11:54:00 -08:00
expr.cpp perf(kernel/expr): fix hash consing performance problem 2017-06-23 12:41:35 -07:00
expr.h perf(kernel/expr): fix hash consing performance problem 2017-06-23 12:41:35 -07:00
expr_cache.cpp refactor(kernel): add expr_cache 2015-02-03 14:59:55 -08:00
expr_cache.h refactor(kernel): add expr_cache 2015-02-03 14:59:55 -08:00
expr_eq_fn.cpp feat(kernel): add let-expressions to the kernel 2016-02-29 16:40:17 -08:00
expr_eq_fn.h feat(library/type_context): allow us to control whether binder information is taken into account or not when caching type information 2016-08-01 16:34:07 -07:00
expr_maps.h feat(library/type_context): allow us to control whether binder information is taken into account or not when caching type information 2016-08-01 16:34:07 -07:00
expr_pair.h feat(library/type_context, frontends/lean/elaborator): type classes with output parameters 2017-01-30 18:32:54 -08:00
expr_sets.h perf(kernel/expr_eq_fn): use thread local cache, and avoid memory allocation/deallocation 2014-10-17 16:44:20 -07:00
ext_exception.h chore(util,kernel,library): clang warnings 2017-02-17 20:01:34 -08:00
find_fn.h refactor(kernel/find_fn): simplify find_fn module 2014-07-23 18:09:58 -07:00
for_each_fn.cpp feat(kernel): add let-expressions to the kernel 2016-02-29 16:40:17 -08:00
for_each_fn.h refactor(kernel/for_each_fn): simplify module interface 2014-07-23 18:16:41 -07:00
formatter.cpp fix(*): remove unnecessary null pointer checks 2015-03-28 12:16:39 -07:00
formatter.h feat(library/type_context): better error messages 2016-09-28 15:59:43 -07:00
free_vars.cpp feat(kernel): add compilation flag for disabling "free var range" optimization 2017-02-21 19:40:56 -08:00
free_vars.h refactor(kernel/expr): remove dead code 2014-10-16 13:09:26 -07:00
init_module.cpp fix(frontends/lean/elaborator, kernel/error_msgs): (re-)activate distinguishing_pp_options 2017-01-30 11:54:00 -08:00
init_module.h refactor(*): explicit initialization/finalization for serialization 2014-09-22 15:26:41 -07:00
instantiate.cpp feat(kernel): add compilation flag for disabling "free var range" optimization 2017-02-21 19:40:56 -08:00
instantiate.h feat(kernel/instantiate): add helper function 2016-08-14 16:16:03 -07:00
kernel_exception.cpp fix(library/tactic/eval,kernel/kernel_exception): hide internal definition name on eval_expr type error 2017-03-27 13:42:08 -07:00
kernel_exception.h fix(library/tactic/eval,kernel/kernel_exception): hide internal definition name on eval_expr type error 2017-03-27 13:42:08 -07:00
level.cpp fix(kernel/expr): disable caching by default 2017-03-23 08:57:56 +01:00
level.h feat(kernel,library,frontends/lean,api): remove global universe levels from kernel and APIs 2017-02-08 17:41:44 -08:00
normalizer_extension.cpp refactor(kernel): remove extension_context 2016-03-19 15:15:39 -07:00
normalizer_extension.h refactor(kernel): remove extension_context 2016-03-19 15:15:39 -07:00
pos_info_provider.cpp refactor(*): use + for concatenating format objects 2014-08-24 09:35:25 -07:00
pos_info_provider.h feat(kernel/pos_info_provider): add save_pos_info 2017-03-31 09:40:48 -07:00
replace_fn.cpp fix(kernel/replace_fn): check if running out of stack space at replace_rec_fn 2017-06-04 15:57:11 -07:00
replace_fn.h feat(kernel/replace_fn): add use_cache flag to replace function 2015-02-05 10:49:18 -08:00
scope_pos_info_provider.cpp refactor(*): reduce exception context info from expr to pos_info 2017-02-17 13:45:57 +01:00
scope_pos_info_provider.h refactor(*): reduce exception context info from expr to pos_info 2017-02-17 13:45:57 +01:00
standard_kernel.cpp refactor(library/standard_kernel): move standard kernel into kernel 2017-01-31 09:39:31 +01:00
standard_kernel.h refactor(library/standard_kernel): move standard kernel into kernel 2017-01-31 09:39:31 +01:00
type_checker.cpp fix(kernel/type_checker,library/type_context): add support for macros that cannot be expanded 2017-06-07 08:25:21 -07:00
type_checker.h chore(kernel/type_checker): remove dead code 2017-02-15 18:05:55 -08:00