Implementation and performance of access modifiers in Ruby

75 Views Asked by At

I am doing a little research into access modifiers in dynamic languages and I want to learn more about how Ruby implements them. I am specifically interested in whether or not the access control checks occur at run-time or if there is any ahead-of-time or evaluation-time optimization that happens, perhaps thanks to a just-in-time compilation step. And if there is no such optimization in current Ruby implementations, I'd still be interested to know if this would be possible in theory.

Also, if it's true that private or protected methods require a run-time check when the method is called to ensure that access should be allowed, how significant is the effect on performance? I'm guessing that this run-time check would need to happen for all method calls, including public ones, so does that mean that all method calls are inherently slower than they would be if Ruby didn't have access modifiers?

I realize these are rather technical questions about internals of the Ruby interpreter and that the best way to understand this in detail would be to read the Ruby source code. But I am not a Ruby developer and am more interested in learning the principles that apply to dynamic languages and access modifiers in general, so I'm hoping someone here might be able to share their knowledge of Ruby internals.


Research I have done so far:

  • Some background reading on the implementation of compilers vs. interpreters and static and dynamic type systems (I also have an understanding of how access modifiers work in compiled languages...obviously a bit more fuzzy when it comes to dynamic languages)
  • I came across a book (Extending a dynamic programming language and runtime environment with access control) that talks about this problem in general and also discusses the GemStone Smalltalk VM for Ruby, but I don't know if the implementation details it discusses are also true of the main/official Ruby interpreter. But to be clear, I'm not asking anyone here to read or look at the book, just providing some context.
0

There are 0 best solutions below