Open matklad opened 4 years ago
The maybe_changed_since
implementation for Slot<DB, Q, MP>
reads from the Slot<DB, Q, MP>
, whose layout depends on the used database DB
and key Q::Key
. While the layout likely doesn't depend on the full query Q
as it is used behind a RwLock
, there is no guarantee to this:
cargo llvm-lines
points its finger in the same general direction: https://gist.github.com/matklad/688220f27cd54bf4967838fe5cb1d8f6#file-cargo-llvm-lines
Also seen here:
See also https://github.com/salsa-rs/salsa/pull/231 which does a lot of restructuring and would presumably address this problem.
Seems like this can be closed now?
@jonas-schievink I think we produce some extra monomophisations for Drop
of query table
I think we've solved the rest of the mystery in https://github.com/rust-analyzer/rust-analyzer/issues/10065.
Every crate/codegen-unit that goes from ConcerteDatabase -> dyn DatabaseTrait
generates a copy of vtable. For usual queries, we counter that with our __shim
functions. The problem is that the vtable also includes generated drop. That drop is not only user-provided custom drop, but the standard drop-every-field-in-order glue as well. That glue is what causing us the extra duplication we still see.
EDIT: and jonas-schievink came up with a genious hack for this: https://github.com/rust-analyzer/rust-analyzer/pull/10069
New cargo bloat --release
output:
File .text Size Crate Name
0.2% 0.5% 69.8KiB ide_db ide_db::apply_change::<impl ide_db::RootDatabase>::per_query_memory_usage
0.2% 0.4% 59.2KiB hir_def hir_def::body::lower::ExprCollector::maybe_collect_expr
0.1% 0.3% 50.9KiB hir_ty hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
0.1% 0.3% 47.4KiB proc_macro_srv <proc_macro_srv::abis::abi_1_56::proc_macro::bridge::server::Dispatcher<proc_macro_srv::abis::abi_1_56::proc_macro::bridge::server::MarkedTypes<S>> as proc_macro_srv:...
0.1% 0.3% 39.0KiB proc_macro_srv <proc_macro_srv::abis::abi_1_55::proc_macro::bridge::server::Dispatcher<proc_macro_srv::abis::abi_1_55::proc_macro::bridge::server::MarkedTypes<S>> as proc_macro_srv:...
0.1% 0.2% 38.5KiB proc_macro_srv <proc_macro_srv::abis::abi_1_47::proc_macro::bridge::server::Dispatcher<proc_macro_srv::abis::abi_1_47::proc_macro::bridge::server::MarkedTypes<S>> as proc_macro_srv:...
0.1% 0.2% 27.8KiB rust_analyzer rust_analyzer::config::field_props
0.1% 0.2% 26.1KiB hir_def hir_def::nameres::collector::ModCollector::collect
0.1% 0.2% 24.0KiB rust_analyzer rust_analyzer::cli::flags::RustAnalyzer::parse_
0.1% 0.1% 22.2KiB ide ide::hover::hover
0.1% 0.1% 20.6KiB chalk_solve <chalk_solve::rust_ir::AssociatedTyDatum<I> as chalk_solve::clauses::program_clauses::ToProgramClauses<I>>::to_program_clauses::{{closure}}
0.1% 0.1% 19.9KiB project_model project_model::workspace::ProjectWorkspace::to_crate_graph
0.1% 0.1% 19.0KiB pulldown_cmark pulldown_cmark::parse::Parser::handle_inline_pass1
0.1% 0.1% 18.6KiB rust_analyzer rust_analyzer::main_loop::<impl rust_analyzer::global_state::GlobalState>::handle_event
0.1% 0.1% 18.0KiB hir_ty hir_ty::diagnostics::decl_check::DeclValidator::validate_item
0.0% 0.1% 17.4KiB std std::backtrace_rs::symbolize::gimli::elf::<impl std::backtrace_rs::symbolize::gimli::Mapping>::new::{{closure}}
0.0% 0.1% 17.1KiB ide_assists ide_assists::handlers::extract_function::extract_function
0.0% 0.1% 16.9KiB hir_ty chalk_solve::clauses::builder::ClauseBuilder<I>::push_binders
0.0% 0.1% 16.7KiB ide ide::syntax_highlighting::highlight::element
0.0% 0.1% 16.0KiB rust_analyzer rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run
0.0% 0.1% 15.4KiB mbe mbe::expander::matcher::match_loop_inner
0.0% 0.1% 15.1KiB notify notify::inotify::EventLoop::event_loop_thread
0.0% 0.1% 15.0KiB hir_def hir_def::nameres::collector::collect_defs
0.0% 0.1% 14.9KiB ide_db ide_db::helpers::insert_use::insert_use
0.0% 0.1% 14.8KiB pulldown_cmark pulldown_cmark::parse::FirstPass::parse_block
0.0% 0.1% 14.6KiB std std::backtrace_rs::symbolize::gimli::Cache::with_global
0.0% 0.1% 14.5KiB ide_completion ide_completion::context::CompletionContext::fill
0.0% 0.1% 14.2KiB cargo_metadata? <cargo_metadata::_::<impl serde::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde::de::Visitor>::visit_map
0.0% 0.1% 13.8KiB hir_ty <chalk_ir::Ty<hir_ty::interner::Interner> as hir_ty::display::HirDisplay>::hir_fmt
0.0% 0.1% 13.5KiB rust_analyzer? <rust_analyzer::config::Config as core::clone::Clone>::clone
0.0% 0.1% 13.4KiB rust_analyzer rust_analyzer::config::ConfigData::from_json
0.0% 0.1% 12.9KiB ide_assists ide_assists::utils::gen_trait_fn_body::gen_trait_fn_body
0.0% 0.1% 12.7KiB serde_json serde_json::value::de::visit_object
0.0% 0.1% 12.5KiB rust_analyzer rust_analyzer::main
0.0% 0.1% 12.5KiB ide_db ide_db::search::FindUsages::search
0.0% 0.1% 12.3KiB ide ide::extend_selection::extend_selection
0.0% 0.1% 12.2KiB ide_ssr ide_ssr::matching::Matcher::attempt_match_node
0.0% 0.1% 12.0KiB hir_ty chalk_solve::infer::unify::Unifier<I>::generalize_ty
0.0% 0.1% 12.0KiB cargo_metadata <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_struct
0.0% 0.1% 11.8KiB hir_ty hir_ty::db::HirDatabaseGroupStorage__::new
0.0% 0.1% 11.7KiB rustc_ap_rustc_lexer rustc_ap_rustc_lexer::<impl rustc_ap_rustc_lexer::cursor::Cursor>::advance_token
0.0% 0.1% 11.7KiB syntax syntax::validation::validate
0.0% 0.1% 11.6KiB project_model <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_struct
0.0% 0.1% 11.6KiB hir_ty chalk_solve::clauses::builder::ClauseBuilder<I>::push_binders
0.0% 0.1% 11.5KiB hir_ty hir_ty::infer::pat::<impl hir_ty::infer::InferenceContext>::infer_pat
0.0% 0.1% 11.0KiB rust_analyzer rust_analyzer::to_proto::completion_items
0.0% 0.1% 10.9KiB parser parser::grammar::expressions::atom::atom_expr
0.0% 0.1% 10.6KiB hir_def hir_def::find_path::find_path_inner
0.0% 0.1% 10.3KiB rust_analyzer serde_json::value::de::visit_object
0.0% 0.1% 10.3KiB ide ide::goto_definition::goto_definition
0.0% 0.1% 10.3KiB hir_def hir_def::db::DefDatabaseGroupStorage__::new
0.0% 0.1% 10.1KiB project_model project_model::cargo_workspace::CargoWorkspace::new
0.0% 0.1% 10.1KiB serde_json serde_json::value::de::visit_array
0.0% 0.1% 10.0KiB hir_ty hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect
0.0% 0.1% 10.0KiB hir_ty chalk_recursive::solve::SolveIteration::solve_iteration
0.0% 0.1% 9.9KiB ide_assists ide_assists::utils::gen_trait_fn_body::gen_partial_eq
0.0% 0.1% 9.9KiB hir_ty chalk_solve::clauses::program_clauses_that_could_match
0.0% 0.1% 9.8KiB ide_completion ide_completion::completions::postfix::complete_postfix
0.0% 0.1% 9.7KiB cargo_metadata <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_struct
0.0% 0.1% 9.6KiB hir_ty chalk_recursive::fulfill::Fulfill<I,Solver>::solve
0.0% 0.1% 9.4KiB ide_assists ide_assists::assist_context::Assists::add
0.0% 0.1% 9.3KiB hir_def hir_def::item_tree::lower::Ctx::lower_mod_item
0.0% 0.1% 9.3KiB ide_assists ide_assists::utils::suggest_name::for_variable
0.0% 0.1% 9.3KiB hir_def hir_def::nameres::path_resolution::<impl hir_def::nameres::DefMap>::resolve_path_fp_with_macro_single
0.0% 0.1% 9.2KiB ide_assists ide_assists::utils::gen_trait_fn_body::gen_debug_impl
0.0% 0.1% 9.1KiB std addr2line::ResUnit<R>::parse_lines
0.0% 0.1% 9.1KiB miniz_oxide miniz_oxide::inflate::core::decompress
0.0% 0.1% 9.1KiB ide ide::syntax_highlighting::traverse
0.0% 0.1% 9.0KiB regex_syntax <regex_syntax::hir::translate::TranslatorI as regex_syntax::ast::visitor::Visitor>::visit_post
0.0% 0.1% 8.8KiB ide ide::join_lines::remove_newlines
0.0% 0.1% 8.8KiB rust_analyzer rust_analyzer::caps::server_capabilities
0.0% 0.1% 8.8KiB hir_def hir_def::item_tree::pretty::Printer::print_mod_item
0.0% 0.1% 8.8KiB ide_diagnostics ide_diagnostics::handlers::unlinked_file::unlinked_file
0.0% 0.1% 8.7KiB ide ide::folding_ranges::folding_ranges
0.0% 0.1% 8.7KiB ide_db ide_db::helpers::import_assets::import_for_item
0.0% 0.1% 8.7KiB ide pulldown_cmark_to_cmark::cmark_with_options
0.0% 0.1% 8.6KiB regex_syntax <regex_syntax::hir::translate::TranslatorI as regex_syntax::ast::visitor::Visitor>::visit_class_set_item_post
0.0% 0.1% 8.6KiB parser parser::grammar::items::maybe_item
0.0% 0.1% 8.4KiB ide ide::inlay_hints::inlay_hints
0.0% 0.1% 8.4KiB project_model <serde::__private::de::content::ContentDeserializer<E> as serde::de::Deserializer>::deserialize_struct
0.0% 0.1% 8.4KiB flycheck <serde::__private::de::content::ContentDeserializer<E> as serde::de::Deserializer>::deserialize_struct
0.0% 0.1% 8.4KiB ide pulldown_cmark_to_cmark::cmark_with_options
0.0% 0.1% 8.3KiB hir_def hir_def::import_map::ImportMap::import_map_query
0.0% 0.1% 8.2KiB rust_analyzer rust_analyzer::config::Config::json_schema
0.0% 0.1% 8.2KiB regex_automata regex_automata::minimize::Minimizer<S>::run
0.0% 0.1% 8.2KiB tracing_tree tracing_tree::format::Buffers::indent_current
0.0% 0.1% 8.2KiB ide_assists ide_assists::handlers::extract_function::format_function
0.0% 0.1% 8.2KiB ide_completion ide_completion::completions::trait_impl::complete_trait_impl
0.0% 0.1% 8.1KiB proc_macro_srv <proc_macro_srv::abis::abi_1_56::proc_macro::bridge::api_tags::Method as proc_macro_srv::abis::abi_1_56::proc_macro::bridge::rpc::Encode<S>>::encode
0.0% 0.1% 8.1KiB hir_ty chalk_solve::clauses::builder::ClauseBuilder<I>::push_binders
0.0% 0.1% 8.0KiB rust_analyzer <serde::__private::de::content::ContentRefDeserializer<E> as serde::de::Deserializer>::deserialize_struct
0.0% 0.1% 7.8KiB rust_analyzer rust_analyzer::diagnostics::to_proto::map_rust_diagnostic_to_lsp
0.0% 0.1% 7.8KiB mbe mbe::expander::matcher::match_
0.0% 0.1% 7.7KiB rust_analyzer serde_json::value::de::visit_array
0.0% 0.0% 7.7KiB rust_analyzer core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
0.0% 0.0% 7.7KiB project_model <serde::__private::de::content::ContentDeserializer<E> as serde::de::Deserializer>::deserialize_struct
0.0% 0.0% 7.7KiB flycheck <serde::__private::de::content::ContentDeserializer<E> as serde::de::Deserializer>::deserialize_struct
0.0% 0.0% 7.7KiB dissimilar dissimilar::diff
0.0% 0.0% 7.6KiB ide ide::rename::rename
0.0% 0.0% 7.6KiB hir_expand hir_expand::builtin_macro::option_env_expand
38.7% 89.1% 13.5MiB And 39248 smaller methods. Use -n N to show more.
43.4% 100.0% 15.1MiB .text section size, the file size is 34.8MiB
I've looked at
cargo-bloat
output for rust-analyzer, and I see things likeFull output: https://gist.github.com/matklad/3be59ade1cae624f9705a3c13b1cbfeb