Skip to content

Improve speed by moving function collections to stack arrays #12

@TheDan64

Description

@TheDan64

A common pattern being used looks something like this:

fn inkwell_does_stuff(input: &[&InkwellValue]) {
    let mut input = Vec<LLVMValueRef> = input.iter().map(|val| val.as_value_ref()).collect(); 

    // call LLVM function with raw ptr to input
}

What we're basically doing is taking a bunch of our own types and mapping them to a sequence of raw llvm pointers. The problem is that Vec will allocate on the heap, but this sequence is only needed for the scope of the function and never gets directly returned. So, I think we can improve this pattern by using something like arrayvec which stores the contents on the stack. This should also work really well because we never modify the size of these vectors, just use them as an intermediate data location for LLVM to read from.

Alternatively, if there's a way to just collect into a a stack slice, that would work too.

This might make for a good first PR if anyone's interested since it doesn't require technical knowledge of LLVM, just Rust.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions