gwt performance

Posted on 2011-04-25
Last Modified: 2012-05-11
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?
Question by:bhomass
    LVL 47

    Expert Comment


    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...
    LVL 47

    Expert Comment

    How do they do it in GWT needs to be looked up.
    I know for example that jQuery library is based on prototypes
    LVL 47

    Accepted Solution

    Judging by this:
    GWT uses prototypes extensively, which would be expected, as it was
    developed when JavaScript already had prototypes
    LVL 26

    Assisted Solution

    >> 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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    SharePoint JSOM error 7 32
    PHP Radio Array 4 27
    javascript - pull variable in from other file 1 15
    JQuery tracking event. 3 14
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now