Boxing code generated by opaque types #12011
erikerlandson
started this conversation in
General Discussion
Replies: 1 comment 7 replies
-
It looks like all the boxing comes from the generic parameter |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
(this started as #12009, but is maybe better suited for a discussion than an issue)
scala
I'm working with scala-3.0.0-RC2.
minimal example
Consider this simplified opaque type (
Wrap
) that uses a typeclass to implement operator+
logic.output
If I compile this code, and then look at the byte-code for
object testwrap
, I see the following. It is clear from the byte-code thatWrap
is being stored as a rawInt
(nice), and the inlined type-class compiles down to rawiadd
(also nice). However, the code also invokes quite a lot of boxing and unboxing, and I am trying to work out the trade-off in compute cost from the (un)boxing versus efficiency of storing the raw Int.Expectation
I'm not sure what a realistic expectation is, but I was hoping the compiler could elide the boxing/unboxing, since the only semantically necessary operations are
istore
,iload
andiadd
on the underlying rawInt
values.I am also unsure how much the various calls to the boxing methods cost. They appear to be significant relative to the core integer operations, however I do not know exactly how much.
Beta Was this translation helpful? Give feedback.
All reactions