Skip to content

YJIT: implement optimized codegen for Array#empty? #475

@maximecb

Description

@maximecb

These are fairly common operations on railsbench (and probably liquid as well): see ruby/ruby-bench#123

We defer to send for opt_empty_p:

fn gen_opt_empty_p(
    jit: &mut JITState,
    ctx: &mut Context,
    asm: &mut Assembler,
    ocb: &mut OutlinedCb,
) -> CodegenStatus {
    // Delegate to send, call the method on the recv
    gen_opt_send_without_block(jit, ctx, asm, ocb)
}

And it looks like it should be easy to implement a fast path for both of these methods. We just need to fetch the length and compare against zero. For some embedded strings, we might even be able to know that the string is not empty at compile-time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions