Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize/simplify viable_models file path to class name logic #3589

Merged
merged 1 commit into from
Jan 8, 2023

Conversation

bnix
Copy link
Contributor

@bnix bnix commented Jan 8, 2023

Use String#delete_prefix to reduce object allocations and simplify the existing logic that converts a file path to a class name when loading candidate models during startup. Also, move repeated path creation to respective outer loop to further cut back on string objects.

Profiler setup on a small project

MemoryProfiler.report { RailsAdmin::Config.send(:viable_models) }.pretty_print(to_file: "prof-#{Time.now.to_i}.txt")

Original code:

allocated objects by file
-----------------------------------
     11885  ruby/2.7.6/lib/ruby/2.7.0/pathname.rb
      4180  rails_admin/lib/rails_admin/config.rb

After patch:

allocated objects by file
-----------------------------------
      2141  ruby/2.7.6/lib/ruby/2.7.0/pathname.rb
      1780  rails_admin/lib/rails_admin/config.rb

@coveralls
Copy link

coveralls commented Jan 8, 2023

Coverage Status

Changes unknown
when pulling 81f5377 on bnix:master
into ** on railsadminteam:master**.

@mshibuya mshibuya merged commit ede9870 into railsadminteam:master Jan 8, 2023
@mshibuya
Copy link
Member

mshibuya commented Jan 8, 2023

Awesome, thanks!

jklimke added a commit to 3dcl/rails_admin that referenced this pull request Jun 27, 2023
* 'master' of github.com:railsadminteam/rails_admin: (53 commits)
  fix is_blank and is_present filters for uuid columns (railsadminteam#3629)
  Add support for '%-l' option to Flatpickr. (railsadminteam#3616)
  Fix polymorphic association target classes not set correctly in subclasses
  Fix multiple_carrierwave field spec failing due to mocking
  Fix webpacker build
  Relax Rubocop Metrics/ClassLength threshold
  Version 3.1.2
  Postpone introduction of the new event name `rails_admin:dom_ready`
  Fix install failing with importmap setup
  Fix to show non-eager-loaded models which are explicitly configured
  Change dom_ready event name to use colon as the separator
  Restore caching in RailsAdmin::Config::Model#excluded? (railsadminteam#3587)
  Update GitHub Actions Badge URL
  Optimize file path to class name conversion (railsadminteam#3589)
  Switch to the safe navigation operator in spec files (railsadminteam#3588)
  Fix typo: Envinronment ==> Environment (railsadminteam#3586)
  Enable RuboCop Style/Encoding and apply auto-fixes (railsadminteam#3585)
  Add CI testing for Ruby 3.2 (railsadminteam#3583)
  Version 3.1.1
  Fix some typos (railsadminteam#3580)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants