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

Use a dedicated object for runtime state #4399

Merged
merged 7 commits into from
Apr 7, 2023
Merged

Conversation

rmosolgo
Copy link
Owner

Setting the current runtime state is a really hot path. This simplifies it so that, rather that creating a hash to store in Thread.current, we store the Runtime instance itself, using instance variables for the relevant bits of state. I think instance variables will be faster than hash keys.

  $ be rake bench:profile_large_result
  # ...
  Calculating -------------------------------------
  Querying for 1000 objects
-                           3.506  (± 0.0%) i/s -     18.000  in   5.198419s
+                           4.095  (± 0.0%) i/s -     21.000  in   5.129366s

@rmosolgo
Copy link
Owner Author

Ok ... I think the problem is, a single Runtime can be running in multiple fibers "at once" (concurrently, not in parallel), and then leftover state in instance variables leaks between fibers. Phew!

@rmosolgo rmosolgo changed the title Use a Runtime instance for runtime state Use a dedicated object for runtime state Apr 7, 2023
@rmosolgo rmosolgo added this to the 2.0.21 milestone Apr 7, 2023
@rmosolgo rmosolgo merged commit cb8a6f9 into master Apr 7, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant