Description
There is a lot of room to improve the performance of Hyperlight. Here are some ideas, roughly ordered by the amount of work required to implement them (from low to high):
-
Avoid unnecessary memory copies: Currently, we make many redundant memory copies when transferring data in and out of the guest. While we're using
flatbuffers
for serialization, we're not leveraging its full benefits. APIs such ascall_guest_func
should accept parameters by reference instead of by value, since the data needs to be serialized anyway. -
Eliminate the per-sandbox hypervisor thread: We spawn a dedicated "hypervisor_handler" thread for each sandbox, which introduces significant context-switching overhead. If we can safely cancel a running VM's execution, we may be able to eliminate this thread entirely.
-
Snapshot and reuse initialized guests: When running the same guest binary across many sandboxes, we could significantly boost performance by allowing users to snapshot an initialized guest and create new guests from that snapshot. This would avoid the overhead of initializing each sandbox from scratch. By mapping the snapshot’s memory into the guest as read-only and using copy-on-write (COW) page faults, we could for example skip reloading the guest binary entirely.