Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to access ivars of classes/modules #5006

Merged
merged 3 commits into from
Oct 22, 2021
Merged

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Oct 22, 2021

if an ivar of a class/module refer to a shareable object, this ivar
can be read from non-main Ractors.

@ko1 ko1 force-pushed the ractor_relax_class_ivar branch 2 times, most recently from f7bd109 to 9e358e4 Compare October 22, 2021 08:54
if an ivar of a class/module refer to a shareable object, this ivar
can be read from non-main Ractors.
@ko1
Copy link
Contributor Author

ko1 commented Oct 22, 2021

prelude: |
  class C
    @a = 1
    def self.a
      _a = @a; _a = @a; _a = @a; _a = @a; _a = @a;
      _a = @a; _a = @a; _a = @a; _a = @a; _a = @a;
    end
  end
benchmark:
  vm_ivar_of_class: |
    a = C.a
loop_count: 30000000
                  vm_ivar_of_class
               master:   6665015.5 i/s
             modified:   5799075.6 i/s - 1.15x  slower

This patch makes ivar of class x1.15 slower. I think it is acceptable.
No other impact (set/get on the following are not stable).

Calculating -------------------------------------
                        modified      master
         vm_ivar_init     7.159M      7.223M i/s -     30.000M times in 4.190535s 4.153643s
     vm_ivar_of_class     5.824M      6.671M i/s -     30.000M times in 5.151327s 4.496804s
vm_ivar_init_subclass     2.272M      2.297M i/s -      3.000M times in 1.320403s 1.306288s
          vm_ivar_set   154.100M    168.416M i/s -     30.000M times in 0.194678s 0.178131s
              vm_ivar   138.971M    137.498M i/s -     30.000M times in 0.215872s 0.218185s

Comparison:
                      vm_ivar_init
               master:   7222575.1 i/s
             modified:   7158991.2 i/s - 1.01x  slower

                  vm_ivar_of_class
               master:   6671404.9 i/s
             modified:   5823742.4 i/s - 1.15x  slower

             vm_ivar_init_subclass
               master:   2296584.0 i/s
             modified:   2272032.8 i/s - 1.01x  slower

                       vm_ivar_set
               master: 168415514.3 i/s
             modified: 154100401.3 i/s - 1.09x  slower

                           vm_ivar
             modified: 138971409.5 i/s
               master: 137497896.1 i/s - 1.01x  slower

benchmark for a class's ivar setter
@ko1
Copy link
Contributor Author

ko1 commented Oct 22, 2021

             vm_ivar_of_class_set
              master:   7296353.0 i/s
            modified:   6880438.4 i/s - 1.06x  slower

setter is x1.06 slower.

doc/ractor.md Outdated

Otherwize, only the main Ractor can access instance variables of shareable objects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Otherwize, only the main Ractor can access instance variables of shareable objects.
Otherwise, only the main Ractor can access instance variables of shareable objects.

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@ko1 ko1 merged commit df9fac5 into ruby:master Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants