Avoid IntRef and other overheads in ScalaRuntime.{toArray, toObjectArray}#8688
Avoid IntRef and other overheads in ScalaRuntime.{toArray, toObjectArray}#8688retronym merged 3 commits intoscala:2.12.xfrom
ScalaRuntime.{toArray, toObjectArray}#8688Conversation
| } | ||
| } | ||
| xs foreach copier | ||
| copier.arr |
There was a problem hiding this comment.
Using an iterator seems more natural - is there a reason not to?
There was a problem hiding this comment.
That does seem unnatural. But I'm reminded there is still no lint for Ref creation.
There was a problem hiding this comment.
I just wrote it is a for loop, because the original was like that. I am not sure where this is implicitly called from. I have changed it to an iterator
Regarding the Ref creation - there are 152 matches for var .*\n[\W]*for regex in the codebase. Some of these are in comments and false matches, but there are lots of patterns that it doesn't pick up
Most of the cases that I see in library and compiler are ref creation.
We just did this case because we see a few 00Gb of IntRef, BooleanRef and ObjectRef and trying to squash them
There was a problem hiding this comment.
@som-snytt I'm reminded people keep asking for one. #8691
3e29f4e to
2ef4752
Compare
hrhino
left a comment
There was a problem hiding this comment.
What's a few hundred gigs between friends?
|
Isn't storage cheap? Oh, this is memory. Then I guess: are you saying 640 K wasn't enough? |
|
I changed my previous vote from heart to rocket. |
|
👀 as in roll. |
🙄 as in, "that's just the way 🙄 " |
|
@mkeskells I couldn't find any call to the We do emit calls to |
Instead, extends the type-case on the src array to separately
deal with each type of primitive array, which can call into
a specialized variant of the loop.
I've also added a special case for empty arrays.
This compiles as:
```
// access flags 0x1A
private final static copy$mCc$sp$1([C)[Ljava/lang/Object;
// parameter final src
ALOAD 0
ARRAYLENGTH
ISTORE 1
ILOAD 1
ICONST_0
IF_ICMPNE L0
GETSTATIC scala/Array$.MODULE$ : Lscala/Array$;
INVOKEVIRTUAL scala/Array$.emptyObjectArray ()[Ljava/lang/Object;
ARETURN
L0
ILOAD 1
ANEWARRAY java/lang/Object
ASTORE 2
ICONST_0
ISTORE 3
L1
ILOAD 3
ILOAD 1
IF_ICMPGE L2
ALOAD 2
ILOAD 3
ALOAD 0
ILOAD 3
CALOAD
INVOKESTATIC scala/runtime/BoxesRunTime.boxToCharacter (C)Ljava/lang/Character;
AASTORE
ILOAD 3
ICONST_1
IADD
ISTORE 3
GOTO L1
L2
ALOAD 2
ARETURN
MAXSTACK = 4
MAXLOCALS = 4
```
|
I've pushed a change to Now: |
ScalaRuntime.{toArray, toObjectArray}
|
@lrytz Could you please review my additional commits? |
|
They LGTM. I still wonder about how the |
Avoid IntRef and other overheads in `ScalaRuntime.{toArray, toObjectArray}`
Avoid IntRef and other overheads in `ScalaRuntime.{toArray, toObjectArray}`
No description provided.