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

  • 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?
  • 3
2 Solutions

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




ans so on...
How do they do it in GWT needs to be looked up.
I know for example that jQuery library is based on prototypes
Judging by this:
GWT uses prototypes extensively, which would be expected, as it was
developed when JavaScript already had prototypes
>> 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.


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