archseer / enigma

An Erlang VM implementation in Rust
Mozilla Public License 2.0
1.05k stars 40 forks source link

Loader transform engine #14

Open archseer opened 5 years ago

archseer commented 5 years ago

Beam implements a transform engine that transforms beam opcodes during the load phase, that way they can implement optimizations that are independent of the OTP version.

https://github.com/erlang/otp/blob/master/erts/emulator/internal_doc/beam_makeops.md

The problem is, it's a large perl script that generates a bunch of C arrays. The loader then uses that array as a series of simple instructions in state machine. The state machine part should be easy, for the generator, we might just fork the perl script to generate rust arrays. Or implement some form of a rust codegen.

https://github.com/erlang/otp/blob/49eb25c80514b1e221cc516c423bbc45ba7cc107/erts/emulator/beam/beam_load.c#L5207

This is a time consuming issue, but will yield a lot of performance improvements (optimize bif calls, instruction combining, etc).

archseer commented 5 years ago

Work has started via proc_macro in https://github.com/archseer/enigma/tree/transform-engine