Commit 2c6590d
committed
Speed up
Some tests by Matt had cases where `.nn` figured prominently in the flamegraph.
I optimized it so that the fast path is streamlined and inlined.
In the following test code:
```
def x: String | Null = "abc"
val y = x.nn
```
the new implementation is
```
10: getstatic #20 // Field MODULE$:LTest$;
13: invokevirtual #24 // Method x:()Ljava/lang/String;
16: astore_0
17: getstatic #29 // Field scala/runtime/Scala3RunTime$.MODULE$:Lscala/runtime/Scala3RunTime$;
20: aload_0
21: invokevirtual #33 // Method scala/runtime/Scala3RunTime$.nn:(Ljava/lang/Object;)Ljava/lang/Object;
24: checkcast #35 // class java/lang/String
27: putstatic #37 // Field y:Ljava/lang/String;
```
The previous implementation was two bytes shorter, but contained in the critical path
- A call to a ScalaRuntime method, which was not inlineable by the JIT compiler due to its size,
- A conversion of a cmparison to a Boolean value (not sure this matters)
- A cast from the return type `Object` to the actual type..nn
1 parent cec9aa3 commit 2c6590d
File tree
2 files changed
+10
-2
lines changed- library/src/scala/runtime
- stdLibPatches
2 files changed
+10
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
0 commit comments