Repository navigation
feat: option to drop compiled function bodies - #251
Closed
andreas-karlsson wants to merge 1 commit into
Closed
andreas-karlsson wants to merge 1 commit into
andreas-karlsson wants to merge 1 commit into
Conversation
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #249.
Adds
withDropCompiledFunctionBodies(boolean)toMachineFactoryCompiler.Builder. When it's enabled,compile()drops the parsed bodies of compiled functions from the module and keeps only the ones the interpreter may still run: the interpreted functions, plus any function they reach through tail calls. Nothing is dropped if an indirect tail call makes those targets unknown, or when the compilation is loaded from the cache.The module is changed in place (
WasmModule.dropFunction), so it can only be run with the returned machine factory afterwards. Accessing a dropped body throws anIllegalStateException.Heap after compile, on two of our modules:
mainParse and compile times are unchanged.
Other things I tried:
A note about the compiler modifying the
WasmModule.I thought this was unacceptable at first and jumped through hoops to avoid it. In the end I've accepted that the compiler "cannibalizes" the module. One API change that would avoid it is a new type
CompiledWasmModulethat is both aWasmModuleand a machine factory (Function<Instance, Machine>).compile()could return a copy of the module with the compiled bodies dropped, leaving the input untouched, and anInstancecould use it as its default machine factory:It would require
WasmModuleto be non-final, and the new type is confusingly similar to the existingCompiledModule, which might be merged into it. It also breaks binary compatibility: code compiled against an older version, a library for example, fails withNoSuchMethodErrorwhen run with the newer one, becausecompile()'s signature includes its return type. If you think this is still preferable, I'm happy to evolve the PR in that direction.