Potentially simple optimization when creating ObjectLiterals

79 views
Skip to first unread message

Paul Stockley

unread,
May 1, 2016, 9:30:09 AM5/1/16
to GWT Contributors
When you define an object literal as

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name="Object")
public class SomeObjLiteral {
}

Calling new on this results in the following javascript code 'new $wnd.Object'. You could just emit {} instead. 
It is surprising the number times you see this code especially for React code bases and when dealing with JSON structures. 
Is it worth filing an issue?

Ray Cromwell

unread,
May 1, 2016, 10:06:34 PM5/1/16
to google-web-toolkit-contributors
A quick fix would be, in a linker, to substitute "new $wnd.Object"
with "{}". It's possible to write a peephole pass to fix this in the
Compiler, but I think given the number of people clamoring for GWT 2.8
and the other more pressing issues, this would be low on the totem
pole.
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-co...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/e1388465-ce9f-4bd9-8846-d4de7dc635f8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Paul Stockley

unread,
May 2, 2016, 9:03:14 AM5/2/16
to GWT Contributors
Thanks. definitely wouldn't hold up 2.8 for it. Are you planning on doing any more compiler enhancements after 2.8 or is it all hands on deck for J2CL?


On Sunday, May 1, 2016 at 10:06:34 PM UTC-4, Ray Cromwell wrote:
A quick fix would be, in a linker, to substitute "new $wnd.Object"
with "{}". It's possible to write a peephole pass to fix this in the
Compiler, but I think given the number of people clamoring for GWT 2.8
and the other more pressing issues, this would be low on the totem
pole.


On Sun, May 1, 2016 at 6:30 AM, Paul Stockley <pstoc...@gmail.com> wrote:
> When you define an object literal as
>
> @JsType(isNative = true, namespace = JsPackage.GLOBAL, name="Object")
> public class SomeObjLiteral {
>
> }
>
>
> Calling new on this results in the following javascript code 'new
> $wnd.Object'. You could just emit {} instead.
>
> It is surprising the number times you see this code especially for React
> code bases and when dealing with JSON structures.
>
> Is it worth filing an issue?
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Reply all
Reply to author
Forward
0 new messages