Class: Hone::Patterns::DynamicIvarGet
- Defined in:
- lib/hone/patterns/dynamic_ivar_get.rb
Overview
Pattern: instance_variable_get("@#name")
Often paired with dynamic instance_variable_set. Suggests the code is using ivars as a dynamic key-value store, which hurts JIT.
Impact: Significant with YJIT, none without
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#add_finding, inherited, #initialize, scan_file
Constructor Details
This class inherits a constructor from Hone::Patterns::Base
Instance Method Details
#visit_call_node(node) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hone/patterns/dynamic_ivar_get.rb', line 15 def visit_call_node(node) super return unless node.name == :instance_variable_get first_arg = node.arguments&.arguments&.first return unless first_arg return unless first_arg.is_a?(Prism::InterpolatedStringNode) || first_arg.is_a?(Prism::LocalVariableReadNode) add_finding( node, message: "Dynamic instance_variable_get suggests ivars used as key-value store. Use a Hash instead for better YJIT performance.", speedup: "Significant with YJIT, none without" ) end |