Skip to content

Ensure common short functions get inlined #11

@randoragon

Description

@randoragon

This must happen for all O(1) getters such as sp_stack_peek and sp_stack_get. There should be NO reason or incentive to worry about loops such as

for (size_t i = 0; i < stack->size; i++) {
    const int elem = sp_stack_geti(stack, i);
    /* do something with elem */
}

generating a function call every iteration, which is (probably) way slower than accessing stack->data directly. This should be trivially guaranteed.

I'm aware C89 does not support enforcing inlining. But most compilers support attributes which allow this. Staple is and always will be compiler-agnostic, but adding some attributes guarded by compiler-detecting ifdefs should be no problem. A bigger problem might be moving function definitions to headers. In any case, this will require some significant modifications to the lua generate tool.

Also, before anything, a benchmark should be conducted to make sure forcing an inlining actually leads to better performance.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions