You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_docs/internals/specialized-traits.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -342,15 +342,15 @@ but that would make it less generally usable. Another alternative is to optimize
342
342
defsumElems(xs: Vector[Int]):Int=
343
343
valfaster: faster.Vector[Int] |Null= xs match
344
344
casexs: faster.Vector[_] => xs
345
-
case _ =>xs
345
+
case _ =>null
346
346
vari=0
347
347
varsum=0
348
348
while i < xs.length do
349
349
sum += (if faster !=nullthen faster(i) else xs(i))
350
350
i +=1
351
351
sum
352
352
```
353
-
That would avoid the boxing at the cost of a type test in the computation of `faster` and a null test in the call of `apply`. The single type test would be amortized over possibly many calls in the loop. We could do even better by generating a bit more code, splitting the whole loop:
353
+
That would avoid the boxing at the cost of a type test in the computation of `faster` and a null test in the call of `apply`. The type test would be amortized over possibly many calls in the loop. We could do even better by generating a bit more code, splitting the whole loop:
354
354
```scala
355
355
defsumElems(xs: Vector[Int]):Int=
356
356
valfaster: faster.Vector[Int] |Null= xs match
@@ -373,7 +373,7 @@ The example has shown that it is possible to have code over possibly specialized
373
373
The boilerplate could be generated automatically by an optimization phase in the compiler. Essentially when compiling methods that take parameters whose type is a class
374
374
that's annotated with `specializedBy`, we can do the path splitting automatically in an optimization step. The optimization would first analyze the body of the method to decide which path splitting strategy to use.
375
375
376
-
I believe the three steps I have outlined could overcome most of the performance penalties imposed by existing unspecialized class hierarchies like collections, making their performance comparable to languages that use global monomorphization.
376
+
I believe the three tweaks I have outlined could overcome most of the performance penalties imposed by existing unspecialized class hierarchies like collections, making their performance comparable to languages that use global monomorphization.
0 commit comments