[WIP] Issue 1541: stack allocation escape analysis in ClangGen#1632
Draft
johnynek wants to merge 1 commit into
Draft
[WIP] Issue 1541: stack allocation escape analysis in ClangGen#1632johnynek wants to merge 1 commit into
johnynek wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1632 +/- ##
==========================================
- Coverage 83.84% 83.67% -0.17%
==========================================
Files 146 147 +1
Lines 26870 27394 +524
Branches 6801 6945 +144
==========================================
+ Hits 22528 22922 +394
- Misses 4342 4472 +130 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
WIP prototype for issue #1541: add a stack-allocation optimization pass in
ClangGenthat rewrites eligiblealloc_enumN/alloc_structNcalls toBSTS_STACK_ALLOC_ENUMN/STRUCTNwhen escape analysis determines the value is local.Implemented pieces in this checkpoint:
StackAllocPassincore/src/main/scala/dev/bosatsu/codegen/clang/ClangGen.scala.c_runtime/bosatsu_runtime.h.ClangGenTestcoverage for escaping vs non-escaping constructor cases and single-constructor enum/newtype behavior.Static impact from generated C
Compared generated
test_workspaceC onmainvs this branch:alloc_enumN, N>0andalloc_structN, N>1):1986 -> 1899(saved87, -4.38%)alloc_*calls:3661 -> 3574(saved87, -2.38%)___bsts_c_Bosatsu_l_Collection_l_Queue_l_tests(-25)___bsts_c_Bosatsu_l_List_l_tests(-17)___bsts_c_Bosatsu_l_Collection_l_TreeList_l_tests(-11)Runtime benchmark findings
I ran A/B timings locally on macOS (
mainvs this branch), including generated binaries and custom harnesses.Important finding:
FibBenchis not a good signal for this optimization; itsBosatsu/FibBenchcall path has 0BSTS_STACK_ALLOC_*sites.Results summary
test_exe: no stable effect (small deltas, CI/variance overlaps zero).iters=10, 24 rounds):Current recommendation
This is not merge-ready yet from a performance-benefit standpoint.