Reduce allocations by optimizing branching and black holes #5492
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.
Overview
We've long had optimized Branch enums for one-branch and two-branch cases, but just never emitted them in code-gen.
Cutting down on allocations helps performance a bit by avoiding GCs
Implementation notes
This changes code-gen to use these optimized cases which skips an EnumMap lookup and more importantly, avoids superfluous allocations.
It also NOINLINE's a single black hole value so we're not dynamically allocating those.
Fixes an oversight in codeValidate which caused it to fail on recursive functions.
Dan and I think the failure was always there, but after this change things are stricter Test1 and Test2 are strict in their branches whereas TestW isn't.
Test coverage
Benchmarks: