Skip to content

Conversation

@jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Mar 3, 2022

This aims to fix https://bugs.ruby-lang.org/issues/18269 as well as making GC iseq marking (and anywhere else we iterate through the instructions) faster by avoiding the hash lookup inside rb_vm_insn_addr2insn.

This is done by storing the original instruction values as a byte array on the iseq before they are translated for threading. We can then use those values directly instead of using the hash table from threaded to non-threaded.

The array is per-instruction rather than per-PC-address, so getting the instruction at a specific PC/offset address is awkward and this is designed for iterating the entire iseq. The advantage is that the array is more compact.

The downside of this is that we need to record an extra byte per-vm-instruction.

TODO:

  • Replace remaining uses of rb_vm_insn_addr2insn and similar (To avoid conflicts with YJIT's port, avoiding modifications there)
  • Check memory increase on a large app
  • Should this code path be disabled if token threading is used?
  • Add regression test for Bug18269

cc @nobu @k0kubun @jeremyevans from linked issue. What do you think of this approach?


struct {
uint8_t *insns;
unsigned int size;
Copy link
Member

Choose a reason for hiding this comment

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

What's different between original_insns.size and iseq_size?

Copy link
Member Author

Choose a reason for hiding this comment

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

original_insns.size is the count of instructions in this iseq. iseq_size is the count of instructions + the total count of operands.

@k0kubun
Copy link
Member

k0kubun commented Mar 4, 2022

I can't think of a better approach to fix [Bug #18269], so it seems legit to me.

@jhawthorn
Copy link
Member Author

This is still an option, but I really don't want to make iseq any larger 😅. I think for now we've worked around the issue in other ways.

@jhawthorn jhawthorn closed this Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants