Improve the performance using the hints by rubocop-performance and fasterer
@anew-bhav がすでに取り組んでいます。
2021年5月31日 から。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- ruby
- 領域
- performance
調査の方向性
rubocop-performance と fasterer のレポートに記載されているファイルと行の位置から始め、特に parser、XPath、quickpath、node、element、doctype の各ファイルを確認してください。両方のツールをプロジェクトに対して実行し、動作を維持できるか各提案変更を確認してください。報告された違反に対処し、既存のチェックにも引き続き合格すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
rubocop-performance (see https://github.com/rubocop-hq/rubocop-performance ) says:
Offenses:
/usr/lib/ruby/2.7.0/rexml/attlistdecl.rb:45:7: C: Performance/InefficientHashSearch: Use #key? instead of #keys.include?.
@pairs.keys.include? key
^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/doctype.rb:201:7: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
quoted_string =~ /^[\'\"].*[\'\"]$/ ?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/element.rb:255:43: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
prefix = "xmlns:#{prefix}" unless prefix =~ /^xmlns:/
^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/entity.rb:44:12: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
if stream[2] =~ /SYSTEM|PUBLIC/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/node.rb:56:9: C: Performance/RedundantBlockCall: Use yield instead of block.call.
block.call(node)
^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/node.rb:65:24: C: Performance/RedundantBlockCall: Use yield instead of block.call.
return node if block.call(node)
^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/parseexception.rb:32:67: C: Performance/StringReplacement: Use tr instead of gsub.
err << @source.buffer[0..80].force_encoding("ASCII-8BIT").gsub(/\n/, ' ')
^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/parsers/baseparser.rb:476:25: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
return false if /\AUTF-16\z/i =~ xml_declaration_encoding
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/parsers/pullparser.rb:73:29: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
event[2] unless event[2] =~ /PUBLIC|SYSTEM/
^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/parsers/treeparser.rb:81:54: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
entities[ event[1] ] = event[2] unless event[2] =~ /PUBLIC|SYSTEM/
^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/parsers/xpathparser.rb:304:14: C: Performance/RegexpMatch: Use match? instead of !~ when MatchData is not used.
if path !~ /^\s*\)/
^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/parsers/xpathparser.rb:539:41: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w*]/
^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/ruby/2.7.0/rexml/quickpath.rb:108:49: C: Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.
matches = filter( elements.dup, rest ) if axe_name =~ /-or-self$/u
^^^^^^^^^^^^^^^^^^^^^^^^
49 files inspected, 13 offenses detected
fasterer (see https://github.com/DamirSvrtan/fasterer) says:
validation/relaxng.rb:416 Calling argumentless methods within blocks is slower than using symbol to proc.
validation/relaxng.rb:523 Calling argumentless methods within blocks is slower than using symbol to proc.
parsers/xpathparser.rb:602 For loop is slower than using each.
parsers/baseparser.rb:381 For loop is slower than using each.
formatters/default.rb:70 Calling argumentless methods within blocks is slower than using symbol to proc.
xpath_parser.rb:105 For loop is slower than using each.
xpath_parser.rb:120 For loop is slower than using each.
xpath_parser.rb:458 Enumerable#sort is slower than Enumerable#sort_by.
xpath_parser.rb:590 Using each_with_index is slower than while loop.
quickpath.rb:88 Calling argumentless methods within blocks is slower than using symbol to proc.
quickpath.rb:133 Calling argumentless methods within blocks is slower than using symbol to proc.
quickpath.rb:135 Calling argumentless methods within blocks is slower than using symbol to proc.
quickpath.rb:138 Calling argumentless methods within blocks is slower than using symbol to proc.
node.rb:54 Calling blocks with call is slower than yielding.
node.rb:63 Calling blocks with call is slower than yielding.
functions.rb:42 Calling argumentless methods within blocks is slower than using symbol to proc.
element.rb:1068 Hash#fetch with second argument is slower than Hash#fetch with block.
element.rb:1075 Hash#fetch with second argument is slower than Hash#fetch with block.
element.rb:1128 Hash#fetch with second argument is slower than Hash#fetch with block.
element.rb:1212 Hash#fetch with second argument is slower than Hash#fetch with block.
element.rb:1246 Calling argumentless methods within blocks is slower than using symbol to proc.
doctype.rb:283 Use attr_reader for reading ivars.
49 files inspected, 22 offenses detected
- 主要言語
- Ruby
- スター
- 181
- フォーク
- 104
- 平均マージ
- 11時間 3分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/rexml のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
XPath underscored function name is wrongly accepted対応中かも @sjh9714 が 46 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
GantMan/jail-monkey#380 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
voxpupuli/puppet-wireguard#151 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Search accepts any value for `requests_per_page` and `per_page`対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug f:search
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信