Rugged mode loads too many Tree entries
In 11.9, we enabled the Rugged feature flags for a customer. For one large repository, the repository view took over 1.5 minutes to load. A quick profile showed we appear to be loading thousands of tree entries in the repository:
irb(main):005:0> Gitlab::Profiler.print_by_total_time(profiler, max_percent: 60, min_percent: 2)
Measure Mode: wall_time
Thread ID: 69894919800320
Fiber ID: 69894591260060
Total: 117.121966
Sort by: total_time
%self total self wait child calls name
41.47 67.048 48.566 0.000 18.482 443050 Rugged::Tree#each
0.00 62.378 0.000 0.000 62.378 18 *ActiveSupport::Callbacks::Filters::End#call
0.00 62.376 0.000 0.000 62.376 1 ActionController::Rendering#process_action
0.00 62.376 0.000 0.000 62.376 1 AbstractController::Base#process_action
0.00 62.376 0.000 0.000 62.376 1 ActionController::BasicImplicitRender#send_action
0.00 62.220 0.000 0.000 62.220 201 *Kernel#tap
0.00 62.218 0.000 0.000 62.218 1 ActionController::ImplicitRender#default_render
0.00 62.216 0.000 0.000 62.216 1 ApplicationController#render
0.00 62.216 0.000 0.000 62.216 1 ActionController::Instrumentation#render
0.00 62.216 0.000 0.000 62.216 1 Elasticsearch::Rails::Instrumentation::ControllerRuntime#cleanup_view_runtime
0.00 62.216 0.000 0.000 62.216 1 ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime
0.00 62.215 0.000 0.000 62.215 1 ActionController::Instrumentation#cleanup_view_runtime
0.00 62.215 0.000 0.000 62.215 1 <Module::Benchmark>#ms
0.00 62.215 0.000 0.000 62.215 1 <Module::Benchmark>#realtime
0.00 62.215 0.000 0.000 62.215 1 ActionController::Rendering#render
0.00 62.215 0.000 0.000 62.215 1 AbstractController::Rendering#render
0.00 62.215 0.000 0.000 62.215 1 ActionController::Renderers#render_to_body
0.00 62.215 0.000 0.000 62.215 1 ActionController::Rendering#render_to_body
0.00 62.215 0.000 0.000 62.215 1 ActionView::Rendering#render_to_body
0.00 62.215 0.000 0.000 62.215 1 ActionController::Streaming#_render_template
0.00 62.215 0.000 0.000 62.215 1 ActionView::Rendering#_render_template
0.00 62.214 0.000 0.000 62.214 7 *ActionView::Renderer#render
0.00 62.214 0.000 0.000 62.214 2 *ActionView::Renderer#render_template
0.00 62.214 0.000 0.000 62.214 2 *ActionView::TemplateRenderer#render
0.00 62.205 0.000 0.000 62.205 2 *ActionView::TemplateRenderer#render_template
0.00 62.205 0.000 0.000 62.205 2 *ActionView::TemplateRenderer#render_with_layout
0.00 62.204 0.000 0.000 62.204 84 *ActionView::AbstractRenderer#instrument
0.00 62.204 0.000 0.000 62.204 103 *ActionView::Template#render
0.00 62.203 0.000 0.000 62.203 181 *ActionView::Template#instrument
0.00 62.061 0.000 0.000 62.061 1 ActionView::CompiledTemplates#_app_views_projects_show_html_haml___3521423232798037216_69894536647460
0.00 62.058 0.000 0.000 62.058 83 *ActionView::Helpers::RenderingHelper#render
0.00 62.058 0.000 0.000 62.057 82 *ActionView::Renderer#render_partial
0.00 62.055 0.000 0.000 62.055 82 *ActionView::PartialRenderer#render
0.00 62.049 0.000 0.000 62.049 81 *ActionView::PartialRenderer#render_partial
0.00 60.690 0.000 0.000 60.690 1 ActionView::CompiledTemplates#_app_views_projects__home_panel_html_haml___1671617190117463090_69894563017920
0.00 60.690 0.000 0.000 60.690 3 *AutoDevopsHelper#show_auto_devops_callout?
0.00 60.690 0.000 0.000 60.690 3 *Flipper::Feature#off?
0.00 56.366 0.000 0.000 56.366 2 AvatarsHelper#project_icon
0.00 54.239 0.000 0.000 54.239 46 *<Class::Feature>#enabled?
0.00 54.037 0.000 0.000 54.037 1 Repository#tree
0.00 53.786 0.005 0.000 53.781 3538 *Hash#fetch
0.00 53.746 0.000 0.000 53.746 1 ActionView::CompiledTemplates#_app_views_projects__files_html_haml__4106255916450609352_69894522668440
0.00 51.570 0.001 0.000 51.569 161 *Gitlab::Utils::StrongMemoize#strong_memoize
0.00 51.522 0.000 0.000 51.522 7 *Tree#readme
0.00 51.520 0.000 0.000 51.520 2 Repository#blob_at
0.00 51.520 0.000 0.000 51.520 2 Gitlab::Git::Repository#blob_at
0.00 51.513 0.000 0.000 51.513 5 Repository#head_tree
0.52 44.750 0.609 0.000 44.141 387710 *Enumerable#find
0.57 28.224 0.666 0.000 27.558 501514 Gitlab::Git::RuggedImpl::Repository#lookup
0.40 27.428 0.465 0.000 26.963 501518 Rugged::Repository#rev_parse
23.02 26.963 26.960 0.000 0.003 501518 <Class::Rugged::Object>#rev_parse
0.11 23.493 0.130 0.000 23.363 58913 *Enumerable#map
0.67 12.174 0.787 0.000 11.387 714008 Gitlab::Git::Tree#initialize
0.01 8.611 0.006 0.000 8.604 1127 *Thread::Mutex#synchronize
0.00 8.121 0.000 0.000 8.120 103 ActionView::Template#compile!
0.00 8.114 0.003 0.000 8.112 78 ActionView::Template#compile
5.31 6.232 6.223 0.000 0.009 3333 Module#module_eval
0.00 4.248 0.000 0.000 4.248 1 ActionView::CompiledTemplates#_app_views_layouts_project_html_haml___3184971530422067605_69894536617180
0.00 3.999 0.000 0.000 3.999 1 ActionView::CompiledTemplates#_app_views_layouts_application_html_haml___285116472384088952_69894512727860
0.00 3.998 0.000 0.000 3.998 1 EE::ApplicationHelper#page_class
0.45 3.018 0.525 0.000 2.492 772468 Gitlab::Git::Tree#path
0.00 2.789 0.001 0.000 2.789 228 *ActionView::Helpers::CaptureHelper#capture
0.66 2.708 0.772 0.000 1.936 831022 Gitlab::EncodingHelper#encode!
0.00 2.700 0.004 0.000 2.696 228 *ActionView::Helpers::CaptureHelper#with_output_buffer
2.09 2.448 2.448 0.000 0.000 772768 <Class::File>#join
* indicates recursively called methods
Edited by Stan Hu