Skip to content

Skip redundant host function registration on reload - #422

Merged
ludfjig merged 2 commits into
hyperlight-dev:mainfrom
ludfjig:skip-host-module-reregistration
Nov 12, 2026
Merged

ludfjig merged 2 commits into
hyperlight-dev:mainfrom
ludfjig:skip-host-module-reregistration

Conversation

@ludfjig

@ludfjig ludfjig commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

get_loaded_sandbox and unload each called RegisterHostModules, although the base snapshot already holds that registration. A load/unload cycle made four guest calls, but only register_handler and RunHandler are needed. In hyperlight-dev/hyperlight-bench#46, kvm-hyperlight-js-reload lost 15% throughput against 0.4.0.

This change registers host functions only when a restored snapshot records different ones than the builder supplies. It then takes a new base snapshot, so later cycles skip registration.

full_lifecycle/add_load_handle_unload:

main this PR
MSHV 415 µs 315 µs
KVM 248 µs 203 µs

KVM stays about 10% slower than 0.4.0 because each guest call costs more in Hyperlight 0.18.

Breaking: the snapshot metadata schema is now 2. Snapshots from 0.5.0 can record host functions their base never registered, so they are rejected and must be recreated.

@ludfjig ludfjig added the kind/bugfix Bug fix label Nov 11, 2026
get_loaded_sandbox and unload each called RegisterHostModules, although
the base snapshot already holds that registration. A load/unload cycle
made four guest calls. Only register_handler and RunHandler are needed.

Register host functions only when a restored snapshot records different
ones than the builder supplies. On add_load_handle_unload this cuts
415 to 315 us on MSHV and 248 to 203 us on KVM.

Bump the snapshot metadata schema to 2, since 0.5.0 snapshots can record
host functions their base never registered.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig
ludfjig force-pushed the skip-host-module-reregistration branch from 95441bf to befbc01 Compare November 11, 2026 22:26
simongdavies
simongdavies previously approved these changes Nov 12, 2026

@simongdavies simongdavies left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions but otherwise LGTM, I think we need to do release notes the same as for hyperlight as this has breaking changes and the move to hyperlight v0.19 will also cause breaking changes, I will look at this later.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig
ludfjig merged commit 397ea36 into hyperlight-dev:main Nov 12, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants