Idea: optimized library pimping

View: New views
3 Messages — Rating Filter:   Alert me  

Idea: optimized library pimping

by Erkki Lindpere-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Idea: optimized library pimping

by Erkki Lindpere-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
>

Re: Re: Idea: optimized library pimping

by Jorge Ortiz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> 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