[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

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?
0
bhomass
Asked:
bhomass
  • 3
2 Solutions
 
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
 
for_yanCommented:
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
 
dpearsonCommented:
>> 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now