Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Class instance variables increase ivar table size on "Class" #153

headius opened this Issue · 1 comment

2 participants


This could be a big problem. Whenever an object defines a new instance variable, we store a name/offset mapping for that variable on the nearest concrete class. In the case of normal objects, this means that singletons can bloat up the number of instance variables on their related class, but in practice that does not happen much. Unfortunately on classes, this means that all classes in the system that set class instance variables are increasing the size of the variable table on the Class class, since that is the nearest concrete class.

system ~/projects/jruby $ jirb
>> class Foo
>> @foo = 1
>> end
=> 1
>> require 'jruby'
=> true
>> cls_j = JRuby.reference(Class)
=> Class
>> cls_j.variable_names.to_a
=> ["__size__", "__member__", "@local", "@RCS_ID", "@debug_level", "@foo", "@java_class", "@java_interfaces"]

In a large app with a lot of class instance variables, this could cause the size of those classes variable arrays to be much larger than they should be.

It's worth noting that the arrays are created lazily, so only classes that set instance vars will ever cause them to be created.

This came up during an IRC discussion about ActiveRecord 3+ scopes, which create singleton classes and set class instance variables extensively.


So I've verified that this is still the case with JRuby, is this really something to care about @headius? It hasn't been much of a problem in the past two years as far as I can tell :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.