Hot Reload - HaxeFoundation/hashlink GitHub Wiki

Starting from HashLink 1.12, hot reload of JIT code is partially supported, although experimental.

Hot Reload

Hot Reload is the capacity to modify at runtime some running program without the need to restart the application. In HashLink, that consists in looking at changed functions, JIT-ing them and patching the calls so they all land on the new version of the function.

Hot Reload in HL has some limitation atm:

  • changes in class fields are not supported : if you add/remove/modify/move a class field, hot reload will fail. This is because some instances might already have been allocated and it would be complex to remap all in-memory objects with new layout.
  • adding new types between compilation is supported but their static variables will not be initialized.
  • it is still experimental and you might experience some bugs after reloading or hot reload might simply not work. I'm interested in very very small (actually tiny 2-3 lines) reproducible samples of hot reload failures so I can improve the support for it. I won't consider larger samples because it takes time to debug these class of issues.

Enabling hot reload

In order to enable hot reload in your program, you need to call the newest hl.Api.checkReload() in your main loop (or if you are using Heaps you can compile with -D hot-reload). This API requires the latest Haxe version (4.3-rc+)

This will perform regular checks on the bytecode file, and in case it's been modified the function will return "true" and the code will be updated.

You also need to enable hot reload in the VM at runtime. This can be done by running hl --hot-reload or by setting hotReload:true in your VSCode launch parameters for HashLink debugger.