Skip to content

Incremental Compilation

Erik McClure edited this page May 27, 2019 · 1 revision

An inNative Environment is re-usable, in that you can modify it's configuration and add modules or embeddings after you've compiled something, and then re-compile it. Currently, you cannot remove a module from an environment - instead, this usually calls for an entirely new environment. However, if you are simply appending a module to be re-compiled, you can take advantage of the Environment's incremental compilation.

Intermediate Caching

The environment stores intermediate compilation results in env->objpath, which are not deleted until DestroyEnvironment() is called. If you add a single module to the environment and call Compile, it will re-use the existing object files in env->objpath, compiling only the new module and simply re-linking them all together. This behavior is primarily intended to be used when compiling .wast files, which can force many compilations whenever a new module is defined in the middle of the script, and it helps speed up execution enormously.

The incremental cache does not know when a module has been modified. If you modify a module and wish to recompile it, you should clear it's cached compilation result using ClearEnvironmentCache(). You can clear specific module caches, or you can pass in a NULL module and clear the entire Environment's cache to start from scratch (this is useful when simply flushing a specific module's cache is not sufficient).

Clearing a cache is useful if you are developing a game and want to re-compile a level's script without restarting your game. Just be sure you free the previous binary before you load the newly compiled one. This will allow you to hotswap scripts without needing to rebuild the Environment every time. Check the External API for more details on ClearEnvironmentCache().