Skip to content

A method for cranelift code-gen to write compiled code on an already allocated memory #13587

@farooqkz

Description

@farooqkz

Hello Hello.

I have an application in which I need to compiled a huge number of programs of different sizes, and then execute each one of them on a large dataset. Also note that the programs change rapidly, so each time I should compile them again.

Currently, I do:

  • Compile each program using cranelift, so I have a CompiledCode
  • Allocate a memory mapped region
  • Copy the bytes of compiled code from buffer of CompiledCode to the memory mapped allocation
  • Make the memmap executable
  • Transmute the memmap into a function
  • Execute the function on the dataset

Typically, there are 1k-10k programs. And memset has become a very big bottleneck in performance.

What I need to do, is allocate a memmap, and then ask cranelift to write bytes on that region. There is compile_and_emit. But it has got two problems, first you are deprecating this method. Second, this wants a Vec<u8> instead of &mut [u8].

The immediate solution to me as an outsider seems keeping the method and changing it to accept a slice instead of a vec. The right solution, I don't know :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    craneliftIssues related to the Cranelift code generator

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions