gwt performance

In java when you instantiate a new object, no added memory is allocated for its methods. in gwt, the java classes are compiled into javascript. the question is does each javascript instance repeat the method code?

In general, when you create a new instance of a javascript object, are the method code repeated?
bhomassAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:
Judging by this:
http://code.google.com/p/google-web-toolkit/wiki/PrototypeChainingOptimization
GWT uses prototypes extensively, which would be expected, as it was
developed when JavaScript already had prototypes
0
 
for_yanCommented:

I guess, there is a distinction. Originally JavaScript had only
instance methods - those were defined in constructior and each
instance carries with it all its methods.

In modern implementation of JavaScript prototypes can  be used
and in these cases only one copy of method for the
object is stored and all instances
inheriting from this prototype use
the same memory space ofr mthod implementations

type JavaScript prototype in Google and you'll of course  see
 plenty of links on this subject

http://stackoverflow.com/questions/4736910/javascript-when-to-use-prototypes

http://mckoss.com/jscript/object.htm

http://timkadlec.com/2008/01/using-prototypes-in-javascript/

ans so on...
0
 
for_yanCommented:
How do they do it in GWT needs to be looked up.
I know for example that jQuery library is based on prototypes
0
 
dpearsonConnect With a Mentor Commented:
>> In general, when you create a new instance of a javascript object, are the method code repeated?

No it's not.  If you think about it that would be very inefficient.  JavaScript looks for all properties of an object (methods, fields etc.) by looking at the local instance first.  If it fails to find an implementation there it walks a chain of pointers up through the equivalent of a class hierarchy until it finds a property which matches.  If nothing matches it returns "undefined".

This model lets you dynamically modify any instance in the JavaScript object graph to add a new method (or field) while still keeping memory usage efficient.  So don't worry, you're essentially paying the same price for memory usage in JavaScript as you would in Java.  The big difference is more on execution speed then memory model.

Doug
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.