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 memory usage #8947

Merged
merged 1 commit into from
Oct 26, 2020
Merged

Optimize memory usage #8947

merged 1 commit into from
Oct 26, 2020

Conversation

fatkodima
Copy link
Contributor

bin/rubocop-profile --memory lib/rubocop/cop

Before

Total allocated: 1.14 GB (16969980 objects)
Total retained:  7.35 MB (54861 objects)
....
allocated memory by file
....
  47.01 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/team.rb   (1)
  23.77 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/util.rb   (2)
  19.01 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/corrector.rb   (3)
  13.81 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/naming/predicate_name.rb   (4)
  11.79 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/mixin/line_length_help.rb   (5)
   7.71 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/style/semicolon.rb   (6)
   7.45 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/magic_comment.rb   (7)
....

After

Total allocated: 1.09 GB (16268498 objects)
Total retained:  7.32 MB (54780 objects)
....
allocated memory by file
  37.51 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/team.rb   (1)
  13.77 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/util.rb   (2)
   8.13 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/mixin/line_length_help.rb   (5)
   1.99 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/style/semicolon.rb   (6)
   1.58 MB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/cop/naming/predicate_name.rb   (4)
 612.31 kB  /Users/fatkodima/Desktop/oss/rubocop/lib/rubocop/magic_comment.rb   (7)

So, another 5% of memory savings.

@@ -9,6 +9,8 @@ module Cop
# The nodes modified by the corrections should be part of the
# AST of the source_buffer.
class Corrector < ::Parser::Source::TreeRewriter
NOOP_CONSUMER = ->(diagnostic) {} # noop
Copy link
Contributor

Choose a reason for hiding this comment

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

Good. I have a PR I need to finish with a better interface, but this is good in the meantime 👍

@@ -194,7 +194,7 @@ def frozen_string_literal; end
class SimpleComment < MagicComment
# Match `encoding` or `coding`
def encoding
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/i)
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/io)
Copy link
Contributor

Choose a reason for hiding this comment

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

@marcandre marcandre merged commit 291aec7 into rubocop:master Oct 26, 2020
@marcandre
Copy link
Contributor

Good stuff, thanks!

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.

None yet

2 participants