News for hackers. Stuff that matters.
Re:JIT and Ruby's MJIT by felixarba on Friday December 06, 2019 @07:23PM (#21727504)
Would be interesting to hear why it doesn't play nice with rails yet
Re:JIT and Ruby's MJIT by haimez on Friday December 06, 2019 @07:26PM (#21727523)
Because rails is extremely eager to redefine classes and monkey patch instances by design. This is hostile to almost all JIT models. V8 spends a very large amount of engineering time optimizing specific cases of handling the common cases of this, but it’s non trivial.
Re:JIT and Ruby's MJIT by hsm3 on Friday December 06, 2019 @08:31PM (#21727836)
Aren't most of those shenanigans done early in the VM's lifespan (as Rails boots, actions are called the first time,...), after which the world would be stable, and JIT-related caches wouldn't have to be lost?
Re:JIT and Ruby's MJIT by haimez on Friday December 06, 2019 @11:26PM (#21728468)
Generally yes, and I won’t get into the weeds about how inlined methods can have their inlinedness invalided if you look too hard at or breathe on them- but this isn’t a deterministic process. The first time you touch an ActiveRecord::Model, the database is queried and your classes ARE redefined. It’s not even close to the same ballpark of loading a new class on the JVM, and the stabilizing assumption you’re hoping exists often doesn’t. Death by 1,000 cuts
Re:JIT and Ruby's MJIT by t-writescode on Friday December 06, 2019 @09:54PM (#21728162)
New Rails dev here: I believe the entire ActiveRecord model is constant monkey patching.
Re:JIT and Ruby's MJIT by FooBarWidget on Friday December 06, 2019 @10:13PM (#21728228)
Long time Rails dev here. I believe not. The Rails core devs have long known that monkey patching is not thread safe, and blows Ruby method caches, so they already reserve monkey patching for initialization time.
Re:JIT and Ruby's MJIT by thomasfedb on Saturday December 07, 2019 @01:42AM (#21728876)
I feel that the definition of "monkey patching" doesn't (or shouldn't) cover what Rails does in AR. Monkey patch suggests a change of behaviour over what was initially intended, however dynamic method generation in AR is very-much part of the intended API.

That said, there are plenty of Rails apps that do monkey patch Rails internals, for better or worse.

Re:JIT and Ruby's MJIT by toasterlovin on Friday December 06, 2019 @10:16PM (#21728235)
Do you have something specific in mind? From my understanding of ActiveRecord, most of the method generation should happen the first time the class is defined.
Re:JIT and Ruby's MJIT by viraptor on Saturday December 07, 2019 @03:41AM (#21729198)
Closer to the first time it's used. Schema gets queried and methods get added the moment you do the first query on the model normally.
Re:JIT and Ruby's MJIT by mperham on Saturday December 07, 2019 @09:26AM (#21730399)
This is not true in production, where eager loading is always on.