Tweak getCurrentContext for SPEED#5959
Merged
headius merged 1 commit intojruby:masterfrom Nov 5, 2019
Merged
Conversation
This change reduces the overhead of calling Ruby.getCurrentContext since we still call it in a number of places. * ThreadService now extends ThreadLocal rather than aggregating a ThreadLocal in a field. This eliminates one hop. * All hot-path methods in ThreadService are static. * Restore @kares recursion logic since it does appear faster than an explicit null check loop. On OpenJDK 8 C2 this reduces single-thread getCurrentContext time from around 4ns to around 3.2ns. Other VMs have similar gains. Tested with a trivial benchmark: ```java import org.jruby.Ruby; public class ContextGetter { public static void main(String[] args) { Ruby runtime = Ruby.newInstance(); while (true) { long nanos = System.nanoTime(); for (int i = 0; i < 100_000_000; i++) { runtime.getCurrentContext(); } System.out.println((System.nanoTime() - nanos) / 100_000_000.0); } } } ```
Member
Author
|
Assembly output from this benchmark and this branch on OpenJDK8 C2 is here: https://gist.github.com/headius/ac6ae20bcaa33c9795c3df4decb88dfd Note that the hot path appears to have inlined completely down to line 167, returning the non-null result at that point. This is a Very Good Thing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change reduces the overhead of calling Ruby.getCurrentContext
since we still call it in a number of places.
On OpenJDK 8 C2 this reduces single-thread getCurrentContext time from around 4ns to around 3.2ns. Other VMs have similar gains.
Tested with a trivial benchmark: