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

[Fix #1260] Fix performance regression caused by Rails/UnknownEnv on rails 7.1 #1262

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

lukasfroehlich1
Copy link
Contributor

After upgrading to Rails 7.1 we noticed a significant slowdown of RuboCop (52s -> 3m 52s).

We found that the cache file path for certain files was changing throughout the RuboCop execution, resulting in cache misses. One of the components of the cache file path is the cop config.

When diffing the cop config throughout RuboCops execution we find that "Rails/UnknownEnv"."Environments" is changing:
Screenshot 2024-03-26 at 12 29 52 AM

When Rails/UnknownEnv runs as part of the warm_cache step in RuboCop it mutates the config, which subsequently modifies the file checksums. When RuboCop runs inspect_files it results in cache misses because the cop config is no longer the same.

The code causing the issue:

def environments
  @environments ||= begin
    environments = cop_config['Environments'] || []
    environments << 'local' if target_rails_version >= 7.1
    environments
  end

In this case cop_config['Environments'] is mutated when environments << 'local' runs.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@@ -92,6 +92,15 @@
RUBY
end

it 'does not mutate the cop config' do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is basically the same as the one above. Would ya'll prefer if I merged it with the one above and change the test description to be: "accepts local as an environment name and does not mutate the cop config"?

@lukasfroehlich1 lukasfroehlich1 changed the title [Fix #1260] Fix performance regression caused by Rails/UnknownEnv o… [Fix #1260] Fix performance regression caused by Rails/UnknownEnv on rails 7.1 Mar 26, 2024
@koic koic merged commit b59d666 into rubocop:master Mar 27, 2024
14 checks passed
@koic
Copy link
Member

koic commented Mar 27, 2024

Thanks for the investigation and the fix!

@lukasfroehlich1 lukasfroehlich1 deleted the fix_unknown_env_mutate branch April 1, 2024 17:27
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.

2 participants