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

Support key stroke in trap key #332

Merged
merged 10 commits into from
Sep 5, 2021

Conversation

aycabta
Copy link
Member

@aycabta aycabta commented Sep 5, 2021

No description provided.

@aycabta aycabta merged commit acbccaf into ruby:master Sep 5, 2021
@aycabta aycabta deleted the support-key-stroke-in-trap_key branch September 5, 2021 20:23
@@ -1,8 +1,59 @@
class Reline::KeyStroke
using Module.new {
refine Integer do
def ==(other)
Copy link
Member

Choose a reason for hiding this comment

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

Could we achieve this another way? Redefining == on integer (even in a refinement) will clear BOP_EQ for integers, making all comparisons slower.

ie. This optimization in MRI will no longer work https://github.com/ruby/ruby/blob/master/vm_insnhelper.c#L1986-L1987

Copy link
Member Author

Choose a reason for hiding this comment

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

Terminal control software often spends more than 99% of its processing time displaying characters to the terminal. Do you have any performance measurement results that show that key processing is the bottleneck and should be improved?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry. The issue isn't in reline's processing, but that this will make Ruby's integer comparisons slower globally. All code will be slower, not just reline.

Here's a hacky demonstration benchmark on latest Ruby trunk:

jhawthorn@zergling:~/src/ruby (int_bop ) [ruby 3.1.0]
$ ruby -r 'benchmark' -e 'p Benchmark.realtime { 10_000_000.times { 1==1;1==1;1==1;1==1;1==1;1==1;1==1;1==1;1==1;1==1 } }'
1.1078672040021047

jhawthorn@zergling:~/src/ruby (int_bop ) [ruby 3.1.0]
$ ruby -r 'benchmark' -rreline -e 'p Benchmark.realtime { 10_000_000.times { 1==1;1==1;1==1;1==1;1==1;1==1;1==1;1==1;1==1;1==1 } }'
4.35402021300979

Copy link
Member Author

Choose a reason for hiding this comment

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

this will make Ruby's integer comparisons slower globally.

Thanks for the concise and clear explanation. I now understand the problem. It looks like binding.irb is going to cause serious problems in Rails applications.

Please wait a bit while we work on it.

Copy link
Member Author

Choose a reason for hiding this comment

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

#347
I did it. I think this problem was pretty bad. I'm glad I could handle it. Thanks again.

Copy link
Member

Choose a reason for hiding this comment

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

Change looks great! Thank you for looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants