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

send-pop optimisation #2100

Open
wants to merge 20 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

add rb_whether_the_return_value_is_used_p()

Looking at how `make rdoc` is working, I noticed that strings
allocated inside of StringScanner#scan (which is called from
lib/rdoc/markup/parser.rb:508, "else @s.scan ...") are becoming
garbages immediately.  Why not make it possible for extension
libraries to know whether the return values are needed or not.  That
way StrigngScanner can avoid generation of such useless strings, to
reduce the GC pressure.
  • Loading branch information...
shyouhei committed Dec 3, 2018
commit 976a94cc5ea7cf42872961d111ed17e74727458d
@@ -527,7 +527,8 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
static VALUE
strscan_scan(VALUE self, VALUE re)
{
return strscan_do_scan(self, re, 1, 1, 1);
int needstr = rb_whether_the_return_value_is_used_p();
return strscan_do_scan(self, re, 1, needstr, 1);
}

/*
@@ -588,7 +589,8 @@ strscan_skip(VALUE self, VALUE re)
static VALUE
strscan_check(VALUE self, VALUE re)
{
return strscan_do_scan(self, re, 0, 1, 1);
int needstr = rb_whether_the_return_value_is_used_p();
return strscan_do_scan(self, re, 0, needstr, 1);
}

/*
@@ -622,7 +624,8 @@ strscan_scan_full(VALUE self, VALUE re, VALUE s, VALUE f)
static VALUE
strscan_scan_until(VALUE self, VALUE re)
{
return strscan_do_scan(self, re, 1, 1, 0);
int needstr = rb_whether_the_return_value_is_used_p();
return strscan_do_scan(self, re, 1, needstr, 0);
}

/*
@@ -682,7 +685,8 @@ strscan_skip_until(VALUE self, VALUE re)
static VALUE
strscan_check_until(VALUE self, VALUE re)
{
return strscan_do_scan(self, re, 0, 1, 0);
int needstr = rb_whether_the_return_value_is_used_p();
return strscan_do_scan(self, re, 0, needstr, 0);
}

/*
@@ -992,6 +992,8 @@ VALUE rb_time_succ(VALUE);
VALUE rb_make_backtrace(void);
VALUE rb_make_exception(int, const VALUE*);

int rb_whether_the_return_value_is_used_p(void);

RUBY_SYMBOL_EXPORT_END

#if defined(__cplusplus)
10 vm.c
@@ -3536,4 +3536,14 @@ vm_collect_usage_register(int reg, int isset)

#endif /* #ifndef MJIT_HEADER */

int
rb_whether_the_return_value_is_used_p(void)
{
const struct rb_execution_context_struct *ec = GET_EC();
const struct rb_control_frame_struct *reg_cfp = ec->cfp;
const VALUE *ep = GET_EP();

return ! VM_ENV_FLAGS(ep, VM_FRAME_FLAG_POPPED);
}

#include "vm_call_iseq_optimized.inc" /* required from vm_insnhelper.c */
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.