Compiler: cache cleanup transformer #11197
Merged
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.
Otherwise on every
finished
hook we might potentially be cleaning up big chunksof the program over and over agin.
Consider this program:
On my machine it takes about a second to compile.
Now this program:
It takes 8.5 seconds to compile! 😱
The reason is that we call
cleanup
on everyfinished
hook, and that ends up creating a newCleanupTransformer
. Every transformer will cleanup calls and their respective target methods (target_defs
), and keep a cache of which have been transformed (many calls might end up hitting the same method, of course.) However, because we create a newCleanupTransformer
on everyfinished
hook, these methods are "cleaned up" over and over again (this could spawn a big chunk of the program, because it goes into those methods, calls in those methods, and target methods of those calls, etc.)I noticed this because the interpreter uses
cleanup
a lot more, and it was taking like 1 minute to create bytecode for the compiler's program, while it took about 20 seconds to generate LLVM code, which was very unreasonable.I know Lucky and other programs use
macro finished
a lot so this might improve compilation times a bit, but I don't expect a huge difference (in this sample program I have 3000 macro finished hooks, maybe a regular program have a dozen of them, I don't know)