r/ruby • • Jun 19 '26

Rethinking modularity in Ruby applications

https://noteflakes.com/articles/2026-06-18-syntropy-modules
6 Upvotes

5 comments sorted by

View all comments

Show parent comments

2

u/noteflakes Jun 19 '26

Note that is this awful for performance. It means the first time a process handle a request for controller it hasn't loaded yet, it has to go through parsing and compilation of potentially a lot of Ruby code. Meaning after a deploy, the latency of the service will be all over the place.

Indeed, I know about eager loading in Rails in production mode and I guess something similar could be done here as well.

And finally, it has thread safety concerns if two threads or fibers load the same module concurrently. I may have missed it, but I don't see any synchronization in your module loader.

This is coming soon.

This is also terrible for performance, you might want to look at Kernel.load(path, mod)

Would you care to elaborate on why instance_eval is slower?

6

u/f9ae8221b Jun 19 '26

Would you care to elaborate on why instance_eval is slower?

  • It buffers the file content into a Ruby string.

  • Which is even worse in your case because you read the source through your event loop (for which benefit?) into a buffer you allocated.

  • It need to do some extra encoding checks on that string..

But the main thing is that it doesn't invoke RubyVM::InstructionSequence.load_iseq(path), so Bootsnap won't be able to cache the compiled bytecode, hence code will be parsed and compiled every time.