cortoproject / corto

A hierarchical object store for connecting realtime machine data with web applications, historians & more
https://www.corto.io
MIT License
86 stars 14 forks source link

Improve implementation of overridable functions #646

Closed SanderMertens closed 6 years ago

SanderMertens commented 6 years ago

Overridable functions are currently implemented with a generated wrapper function that does a lookup for method id and then uses the method id to do a lookup in the method table of the type of the object that the method is being invoked on. Example code:

void someMethod(someType this) {
    corto_type type = corto_typeof(this);
    static int methodId = corto_interface_resolveMethodId(baseClass, "someMethod()");
    corto_method m = corto_interface_resolveMethodById(type, methodId);
    corto_invoke(m, NULL, this);
}

This mechanism introduces an extra frame on the stack, requires generated code even if the method isn't called and adds a little bit of performance overhead to every call. To improve this, the overridable method should be called with a macro.

This will improve performance and remove a stackframe for every overridable method, which makes it easier to debug corto applications. The methodId should be stored on the method object itself, so that it doesn't require a separate lookup.