зеркало из https://github.com/github/ruby.git
Specialize String#byteslice(a, b) (#9939)
* Specialize String#byteslice(a, b) This adds a specialization for String#byteslice when there are two parameters. This makes our protobuf parser go from 5.84x slower to 5.33x slower ``` Comparison: decode upstream (53738 bytes): 7228.5 i/s decode protobuff (53738 bytes): 1236.8 i/s - 5.84x slower Comparison: decode upstream (53738 bytes): 7024.8 i/s decode protobuff (53738 bytes): 1318.5 i/s - 5.33x slower ``` * Update yjit/src/codegen.rs --------- Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
This commit is contained in:
Родитель
a71d1ed838
Коммит
c35fea8509
|
@ -45,6 +45,7 @@ void rb_str_make_independent(VALUE str);
|
|||
int rb_enc_str_coderange_scan(VALUE str, rb_encoding *enc);
|
||||
int rb_ascii8bit_appendable_encoding_index(rb_encoding *enc, unsigned int code);
|
||||
VALUE rb_str_include(VALUE str, VALUE arg);
|
||||
VALUE rb_str_byte_substr(VALUE str, VALUE beg, VALUE len);
|
||||
|
||||
static inline bool STR_EMBED_P(VALUE str);
|
||||
static inline bool STR_SHARED_P(VALUE str);
|
||||
|
|
6
string.c
6
string.c
|
@ -6274,6 +6274,12 @@ str_byte_substr(VALUE str, long beg, long len, int empty)
|
|||
return str2;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_str_byte_substr(VALUE str, VALUE beg, VALUE len)
|
||||
{
|
||||
return str_byte_substr(str, NUM2LONG(beg), NUM2LONG(len), TRUE);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
str_byte_aref(VALUE str, VALUE indx)
|
||||
{
|
||||
|
|
|
@ -224,6 +224,7 @@ fn main() {
|
|||
.allowlist_function("rb_ec_str_resurrect")
|
||||
.allowlist_function("rb_str_concat_literals")
|
||||
.allowlist_function("rb_obj_as_string_result")
|
||||
.allowlist_function("rb_str_byte_substr")
|
||||
|
||||
// From include/ruby/internal/intern/parse.h
|
||||
.allowlist_function("rb_backref_get")
|
||||
|
|
|
@ -5304,6 +5304,37 @@ fn jit_rb_str_bytesize(
|
|||
true
|
||||
}
|
||||
|
||||
fn jit_rb_str_byteslice(
|
||||
jit: &mut JITState,
|
||||
asm: &mut Assembler,
|
||||
_ocb: &mut OutlinedCb,
|
||||
_ci: *const rb_callinfo,
|
||||
_cme: *const rb_callable_method_entry_t,
|
||||
_block: Option<BlockHandler>,
|
||||
argc: i32,
|
||||
_known_recv_class: Option<VALUE>,
|
||||
) -> bool {
|
||||
asm_comment!(asm, "String#byteslice");
|
||||
|
||||
if argc != 2 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Raises when non-integers are passed in
|
||||
jit_prepare_non_leaf_call(jit, asm);
|
||||
|
||||
let len = asm.stack_opnd(0);
|
||||
let beg = asm.stack_opnd(1);
|
||||
let recv = asm.stack_opnd(2);
|
||||
let ret_opnd = asm.ccall(rb_str_byte_substr as *const u8, vec![recv, beg, len]);
|
||||
asm.stack_pop(3);
|
||||
|
||||
let out_opnd = asm.stack_push(Type::TString);
|
||||
asm.mov(out_opnd, ret_opnd);
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn jit_rb_str_getbyte(
|
||||
jit: &mut JITState,
|
||||
asm: &mut Assembler,
|
||||
|
@ -9490,6 +9521,7 @@ pub fn yjit_reg_method_codegen_fns() {
|
|||
yjit_reg_method(rb_cString, "size", jit_rb_str_length);
|
||||
yjit_reg_method(rb_cString, "bytesize", jit_rb_str_bytesize);
|
||||
yjit_reg_method(rb_cString, "getbyte", jit_rb_str_getbyte);
|
||||
yjit_reg_method(rb_cString, "byteslice", jit_rb_str_byteslice);
|
||||
yjit_reg_method(rb_cString, "<<", jit_rb_str_concat);
|
||||
yjit_reg_method(rb_cString, "+@", jit_rb_str_uplus);
|
||||
|
||||
|
|
|
@ -1049,6 +1049,7 @@ extern "C" {
|
|||
pub fn rb_gvar_set(arg1: ID, arg2: VALUE) -> VALUE;
|
||||
pub fn rb_ensure_iv_list_size(obj: VALUE, len: u32, newsize: u32);
|
||||
pub fn rb_vm_barrier();
|
||||
pub fn rb_str_byte_substr(str_: VALUE, beg: VALUE, len: VALUE) -> VALUE;
|
||||
pub fn rb_obj_as_string_result(str_: VALUE, obj: VALUE) -> VALUE;
|
||||
pub fn rb_str_concat_literals(num: usize, strary: *const VALUE) -> VALUE;
|
||||
pub fn rb_ec_str_resurrect(ec: *mut rb_execution_context_struct, str_: VALUE) -> VALUE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче