On 15 mai, 13:03, takayser <[email protected]> wrote:
> Hi
>
> I read the following lines about varargs
> onhttp://sinnema313.wordpress.com/2008/11/16/performance-tuning-a-gwt-a...
>
> Variable argument lists are sometimes quite handy. However, we’ve
> found that they come at a severe performance penalty, because a
> JavaScript array needs to be created to wrap the arguments. So if at
> all possible, use fixed argument lists, even though this may be less
> convenient from a code writing/maintaining perspective.
>
> Is that correct?
in Java, varargs are just syntactic sugar; eventually GWT could use
the fact that the method's argument is a vararg to use the "arguments"
special JS variable (var lastArgAsArray = arguments.slice(3), in case
there are 3 args before the vararg), but it would have to take care of
cases where you call the vararg method with an array instance
(System.out.printf("%s %s %d", new Object[] { "foo", "bar", 5 })); and
it would make method inlining much more difficult (or at least,
different; either by not inlining methods with a vararg, or creating a
JS array as is done today).
And AFAICT, array instantiation isn't that a "severe performance
penalty"; let's just compare the JS code generated by GWT with the one
of a "pure JS" framework *and* the code you would wrote with it
(passing objects as "options", in a way similar to named args isn't
probably much more performant than creating an array compared to
arguments.slice(...))
But as the article you point to says too "Don’t trust rules of thumb,
use a profiler", and compare between:
public void myFunc(String... args)
and
public void myFunc(String arg0, String arg1, String arg2, String
arg3)
+
public void myFunc(String arg0, String arg1, String arg2, String
arg3, String arg4, String arg5)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---