mercredi 22 février 2017

Performance code of wrappering

Question: What is the performance cost of wrapping an object inside of another object? Both in RAM and CPU usage increase from calling the object directly.

Extra Details: I'm working on developing a framework that will wrapper code to isolate plugins from the core implementation of a program. The question keeps popping up in my head "What is the performance cost". I know it will be more than direct access to the code being wrapped. However, I can not seem to find any solid sources or data online to show exactly what results to expect. Which is an issue as I'm developing this to replace the implementation for roughly 40 projects. So when asked what level of overhead is expected in the update I need to have some data.

Also, in case anyone is unsure what I mean by wrapped code. It is the process in which an object is created using an interface that sends all method calls to an object stored in the object. This is done to hide the implementation of an object when the original object can not be modified or changed to include the interface. Below is an example of what I'm talking about.

public class WrapperObject implements WrapperInterface
{
    private SomeObjectClass theObject;

    public WrapperObject(SomeObjectClass theObject)
    {
        this.theObject = theObject;
    }

    public void method1()
    {
        theObject.method1();
    }

    public void method2()
    {
        theObject.method2("someData", 1);
    }
}

As well I do know about JIT in java and other optimization technics the JVM does. I'm asking what I can expect from the overhead of using a system like this for a large project. As I will be wrapping or converting just about everything before it gets to the plugin code. This includes methods that may be called a few 1000 times a second as well as methods only called once.

I will also be building prototypes in the next few days to test performance as well. I'm just looking for some design input to better understand what to expect. Rather than looking blindly at my code making guesses that waste time.

Aucun commentaire:

Enregistrer un commentaire