This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Idea: optimized library pimping

2 replies
Erkki Lindpere
Joined: 2008-12-19,
User offline. Last seen 42 years 45 weeks ago.

While working on my vector math optimizer plugin, I had an idea for
optimizing Pimp-my-library, which would remove the object creation.

For any pimping class, a companion object would be created:

@Pimp class Baz(foo: Foo) {
def bar(arg: Int) = ...
}

would create a companion object

object Baz {
def bar(foo: Foo, arg: Option[Int]) = ...
}

and any use of an implicit function:
implicit def = whatever(foo: Foo) = new Baz(foo)
whatever(foo).bar(None)

would be transformed to
Baz.bar(foo, None)

Does this sound reasonable? Could be easily done using a compiler
plug-in, I think. This misses some other cases of implicit conversions,
but I think it would be useful anyway.

Erkki

Erkki Lindpere
Joined: 2008-12-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Idea: optimized library pimping

On second thought, this object creation probably gets optimized away by
JIT when using escape analysis (since Java 6 update 14). But it would
still be useful in the Client VM.

Erkki Lindpere wrote:
> While working on my vector math optimizer plugin, I had an idea for
> optimizing Pimp-my-library, which would remove the object creation.
>
> For any pimping class, a companion object would be created:
>
> @Pimp class Baz(foo: Foo) {
> def bar(arg: Int) = ...
> }
>
> would create a companion object
>
> object Baz {
> def bar(foo: Foo, arg: Option[Int]) = ...
> }
>
> and any use of an implicit function:
> implicit def = whatever(foo: Foo) = new Baz(foo)
> whatever(foo).bar(None)
>
> would be transformed to
> Baz.bar(foo, None)
>
> Does this sound reasonable? Could be easily done using a compiler
> plug-in, I think. This misses some other cases of implicit
> conversions, but I think it would be useful anyway.
>
> Erkki
>

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: Re: Idea: optimized library pimping
See this SIP: http://jorgeortiz85.github.com/ImplicitClassSIP.xhtml
And the associated mailing list thread: http://www.nabble.com/Pre-SIP:-Implicit-Classes-td22751546.html

--j

On Mon, Jul 20, 2009 at 6:53 PM, Erkki Lindpere <erkki [at] lap [dot] ee> wrote:
On second thought, this object creation probably gets optimized away by JIT when using escape analysis (since Java 6 update 14). But it would still be useful in the Client VM.

Erkki Lindpere wrote:
While working on my vector math optimizer plugin, I had an idea for optimizing Pimp-my-library, which would remove the object creation.

For any pimping class, a companion object would be created:

@Pimp class Baz(foo: Foo) {
 def bar(arg: Int) = ...
}

would create a companion object

object Baz {
 def bar(foo: Foo, arg: Option[Int]) = ...
}

and any use of an implicit function:
implicit def = whatever(foo: Foo) = new Baz(foo)
whatever(foo).bar(None)

would be transformed to
Baz.bar(foo, None)

Does this sound reasonable? Could be easily done using a compiler plug-in, I think. This misses some other cases of implicit conversions, but I think it would be useful anyway.

Erkki


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland