1 hour ago · Tech · 0 comments

Compilers, especially method just-in-time compilers, operate on one function at a time. It is a natural code unit size, especially for a dynamic language JIT: at a given point in time, what more information can you gather about other parts of a running, changing system? I don’t have any data to back this up—maybe I should go gather some—but on average, methods are small. Especially in languages such as Ruby that use method dispatch for everything, even instance variable (attribute, field, …) lookups, they are small. And everywhere. This makes the compiler sad. If we are to continue to anthropomorphize them, compilers like having more context so they can optimize better. Consider the following silly-looking example that is actually representative of a surprising amount of real-world code: class Point def initialize(x, y) @x = x @y = y end def distance(other) Math.sqrt((@x - other.x)**2 + (@y - other.y)**2) end end def distance_from_origin(x, y) Point.new(x, y).distance(Point.new(0, 0))…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.