B&W print-friendly diagrams + tinkerpop-0001 + wave-3 proof sections. Squash of 94 local commits onto remote master.
1.6 KiB
| id | repo | severity | status | created |
|---|---|---|---|---|
| rubocop-0002 | RuboCop | LOW | OPEN | 2026-03-26 |
Defect
File: lib/rubocop/cop/style/redundant_self.rb:62,149
Pattern: @allowed_send_nodes = [] — Array linear scan on every self.x send node
Complexity: O(A × N) per file, where A = self-assignment nodes, N = self-send nodes
Language: Ruby
Description
Style::RedundantSelf tracks nodes representing self.x = / self.x ||= / self.x &&=
assignments in @allowed_send_nodes:
# line 62
@allowed_send_nodes = []
# line 190 — populated on every self.x assignment node
def allow_self(node)
@allowed_send_nodes << node
end
# line 149 — queried on every self.x send node during on_send
def allowed_send_node?(node)
@allowed_send_nodes.include?(node) || ...
end
on_send fires for every send node in the AST. allowed_send_node? calls
@allowed_send_nodes.include?(node) (identity comparison via Array#include?) — O(A) per call,
O(A × N) total.
In practice, A is small for typical Ruby code, keeping this LOW. In generated or DSL-heavy code
with many self.attr= writers the list can grow and the cost compounds.
Fix
# line 62
@allowed_send_nodes = Set.new.compare_by_identity
# line 190
@allowed_send_nodes.add(node)
# line 149 — no change needed; Set#include? is O(1)
Speedup estimate
Negligible on typical Ruby source; 2–5× faster on generated files with many self-assignments.
Work required
- Patch in
defects/rubocop/patch/ - Unit test
- Integration test
- Benchmark
- White paper section (can be grouped with rubocop-0001)