Skip to content

Store method objects in constants - #1033

Merged
tompng merged 1 commit into
masterfrom
store-methods-in-constants
Nov 20, 2024
Merged

tompng merged 1 commit into
masterfrom
store-methods-in-constants

Conversation

@st0012

@st0012 st0012 commented Nov 19, 2024

Copy link
Copy Markdown
Member

It probably won't speed up things significantly, but these are hot paths and we can save a few method calls per completion/input call.

@st0012 st0012 self-assigned this Nov 19, 2024
Comment thread lib/irb/completion.rb Outdated

def eval_instance_variables
::Kernel.instance_method(:instance_variables).bind(eval("self")).call
KERNEL_INSTANCE_VARIABLES.bind(eval("self")).call

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use bind_call(receiver) for the above three.

Comment thread lib/irb/completion.rb Outdated

def eval_global_variables
::Kernel.instance_method(:global_variables).bind(eval("self")).call
KERNEL_GLOBAL_VARIABLES.bind(eval("self")).call

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

::Kernel.global_variables is better because this does not need to look into self

It probably won't speed up things significantly, but these are hot paths
and we can save a few method calls per completion/input call.
@st0012
st0012 force-pushed the store-methods-in-constants branch from bda99c0 to 5bf7e6a Compare November 20, 2024 17:35
@st0012
st0012 requested a review from tompng November 20, 2024 17:35

@tompng tompng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good 👍

@tompng
tompng merged commit f1e25ec into master Nov 20, 2024
@tompng
tompng deleted the store-methods-in-constants branch November 20, 2024 18:59
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 20, 2024
(ruby/irb#1033)

It probably won't speed up things significantly, but these are hot paths
and we can save a few method calls per completion/input call.

ruby/irb@f1e25ec7ae
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