Skip to content

YJIT: implement fast path for kernel#is_a? using type info from context #474

@maximecb

Description

@maximecb

Jimmy suggests that this is a large percentage of time spent on liquid-render.

Many calls to foo.is_a? Integer. We could optimize this if we already have type information from the context, which would result in less code generated and possibly a noticeable performance boost.

Currently, we generate a large chunk of code to call into a C function every time:

  # opt_send_without_block
  # RUBY_VM_CHECK_INTS(ec)
  # regenerate_branch
  0x111db01c6: mov eax, dword ptr [r12 + 0x20]
  0x111db01cb: test eax, eax
  0x111db01cd: jne 0x111db20ec
  # stack overflow check
  0x111db01d3: lea rax, [rbx + 0xb0]
  0x111db01da: cmp r13, rax
  0x111db01dd: jbe 0x111db20ec
  # save PC to CFP
  0x111db01e3: movabs rax, 0x6000010d1250
  0x111db01ed: mov qword ptr [r13], rax
  0x111db01f1: lea rax, [rbx + 0x28]
  # push cme, specval, frame type
  0x111db01f5: movabs rcx, 0x10f8055b0
  0x111db01ff: mov qword ptr [rax - 0x18], rcx
  0x111db0203: mov qword ptr [rax - 0x10], 0
  0x111db020b: mov qword ptr [rax - 8], 0x55550083
  # push callee control frame
  0x111db0213: mov qword ptr [r13 - 0x40], 0
  0x111db021b: mov qword ptr [r13 - 0x10], rax
  0x111db021f: mov qword ptr [r13 - 0x38], rax
  0x111db0223: mov qword ptr [r13 - 0x30], 0
  0x111db022b: mov rcx, qword ptr [rbx]
  0x111db022e: mov qword ptr [r13 - 0x28], rcx
  0x111db0232: mov qword ptr [r13 - 0x18], 0
  0x111db023a: sub rax, 8
  0x111db023e: mov qword ptr [r13 - 0x20], rax
  # switch to new CFP
  0x111db0242: lea rax, [r13 - 0x40]
  0x111db0246: mov qword ptr [r12 + 0x10], rax
  0x111db024b: lea rax, [rbx + 0x10]
  # call C function
  0x111db024f: mov rdi, qword ptr [rax - 0x10]
  0x111db0253: mov rsi, qword ptr [rax - 8]
  0x111db0257: call 0x104f7c1e0
  0x111db025c: mov qword ptr [rbx], rax
  0x111db025f: mov qword ptr [r12 + 0x10], r13

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions