Repository navigation
feat: opt-in runtime memory profiler (#740) - #1341
Merged
Merged
Conversation
godofecht
marked this pull request as ready for review
October 4, 2026 20:18
cursor
Bot
force-pushed
the
cursor/mem-profiling-740-cd11
branch
3 times, most recently
from
October 4, 2026 21:33
dbf6973 to
24c7bd8
Compare
Add a FLOW_MEM_PROFILE runtime in flowc-generated C that counts heap allocations, peak live heap, peak RSS, compiler-temp bytes and copy volume without rewriting workload sources. The #728 harness records those fields from FLOW_MEM_PROFILE_OUT, and the memory/allocation cross-harness rows now do real allocate/copy/RSS work. Co-authored-by: Abhishek Shivakumar <[email protected]>
flow_mem_malloc(32) contains the substring malloc(32), so the negative check now looks for the unwrapped call form. Co-authored-by: Abhishek Shivakumar <[email protected]>
The profiler prelude wraps malloc/realloc, mentions temp lifetime bytes, and uses a constructor attribute. Tighten the attribute and lifetime goldens to the annotation-splice payload, expect the counting wrappers in grow helpers, and refresh hello.c checksums. Co-authored-by: Abhishek Shivakumar <[email protected]>
Co-authored-by: Abhishek Shivakumar <[email protected]>
Co-authored-by: Abhishek Shivakumar <[email protected]>
Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor
Bot
force-pushed
the
cursor/mem-profiling-740-cd11
branch
from
October 4, 2026 22:25
c12add9 to
d154801
Compare
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Fixed-point C after rebasing onto the mem profiler (#1341 / d0e2a8a). bootstrap_from_c.sh --regen (FIXED POINT at gen3) then --verify PASS. Co-authored-by: Abhishek Shivakumar <[email protected]>
7 of 8 tasks
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Rebased onto d0e2a8a (#1341). Source keeps FLOWC_PROFILE plus FLOW_MEM_PROFILE cgen checks. Regen fixed point at gen2; --verify matches compiler/src. Co-authored-by: Abhishek Shivakumar <[email protected]>
7 of 8 tasks
godofecht
added a commit
that referenced
this pull request
Oct 5, 2026
* feat: opt-in per-phase compile timings for flowc (#735) Instrument parse, import resolution, typecheck and codegen behind FLOWC_PROFILE, and teach compile_bench to record cold/warm compile-to-result plus the top fixed vs scaling cost. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: include profile in self-host frontend module lists resolve.flow imports .profile for FLOWC_PROFILE spans. Roundtrip compiled resolve without emitting profile first, so cc failed on implicit flowc_prof_span_begin / FLOWC_PROF_* undeclared. Add profile to roundtrip, gate_lib frontend/self-emit, and g2 fixed-point modules. Scripts only; no bootstrap regen. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after rebase onto mem profiler Rebased onto d0e2a8a (#1341). Source keeps FLOWC_PROFILE plus FLOW_MEM_PROFILE cgen checks. Regen fixed point at gen2; --verify matches compiler/src. Co-authored-by: Abhishek Shivakumar <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Oct 5, 2026
{llvm.noalias} and // flowc.noalias comments change normalized MLIR
digests. Refresh via parity_mlir.flow --record (also records newly
accepted programs from #1341/#1342 and the noalias fixtures).
Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Oct 5, 2026
{llvm.noalias} and // flowc.noalias comments change normalized MLIR
digests. Refresh via parity_mlir.flow --record (also records newly
accepted programs from #1341/#1342 and the noalias fixtures).
Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht
added a commit
that referenced
this pull request
Oct 5, 2026
* perf: emit proven restrict/noalias in C and MLIR backends (#731) Add a fail-closed provenance certificate for local arrays and constant slices, then mark only proven-disjoint internal pointer parameters and unique local pointers with C restrict and MLIR {llvm.noalias}. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: link noalias into stage-A frontend (#731) cgen calls flowc_noalias_* but the module was missing from frontend_modules, the self-emit plan, roundtrip compile_module, and the g2 fixed-point list. Same inventory pattern as type_id / rt_summary. Co-authored-by: Abhishek Shivakumar <[email protected]> * test: re-record parity_mlir corpus after noalias metadata (#731) {llvm.noalias} and // flowc.noalias comments change normalized MLIR digests. Refresh via parity_mlir.flow --record (also records newly accepted programs from #1341/#1342 and the noalias fixtures). Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after noalias rebase onto #1343 Fixed-point C after rebasing onto phase timing (#1343 / c5332d7). bootstrap_from_c.sh --regen (FIXED POINT at gen3) then --verify PASS. Co-authored-by: Abhishek Shivakumar <[email protected]> * test: retarget mlir_defer_addr golden for flowc.noalias (#731) flowc now emits // flowc.noalias on proven-local MLIR allocas. Re-record the mlir_commands expected text so the check matches without weakening noalias/restrict emission. Co-authored-by: Abhishek Shivakumar <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
This was referenced Oct 5, 2026
godofecht
added a commit
that referenced
this pull request
Oct 7, 2026
Port of the startup cohort from the original #1410 branch onto main after #1265 (native baselines). The startup_* rows reuse the cold sources and twins, build the Flow program before timing, and every row now carries a timing_scope. The draft's profile flag is dropped: main already profiles only the memory suite (#1341).
8 tasks done
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.
Intent
Part of #740 (parent #727). Related: #728, #669.
First useful slice of runtime memory instrumentation so #728-style collection can record heap allocation count/bytes, peak live heap, peak RSS, compiler-temp bytes and copy volume without rewriting workload sources.
This ports the
archive/feat/740-mem-profilingdesign to flowc: an opt-inFLOW_MEM_PROFILEruntime in generated C. When the variable is unset the program pays one predictable branch per routed allocation and prints nothing. When set, it writes a human report plus parseablekey: valuelines to stderr, or toFLOW_MEM_PROFILE_OUT.Overlap check
Overlap / dependency notes: No open PR implements #740. The retired Python reference lives at
archive/feat/740-mem-profiling. Nearby #1337 (now on main) fills string/IO harness rows; this PR wires counters rather than overlapping that work. #1265/#1267/#1268 touch the harness for native/parallel/cold-start, not allocator counters. Rebased onto main after #1339 (SIMD), #1340 (type identity), #1337 (string concat / buffered I/O), and #1342 (cross-module@rt_safe/@lifetimesummaries).__flowc_str_concatnroutes throughflow_mem_malloc.FLOW_MEM_PROFILE, SIMD helpers,type_family_id/alignof, and RT summaries are all present.What changed
malloc/calloc/realloc/free/memcpyand compiler-injected heap (string concat, n-way__flowc_str_concatn,array<T>(N), sort scratch, escaping closures) route through counting wrappers. Peak RSS comes fromgetrusage. Stack/arena promotion and per-site copy attribution are labelled deferred (need [MLIR Opt] Static memory lifetime scheduling and zero-runtime allocation #669)../flow tool bench_harnesssetsFLOW_MEM_PROFILE=1andFLOW_MEM_PROFILE_OUTon every measured subject and recordsallocations,heap_bytes,peak_live_heap,temp_bytes,copiesandmedian_rss_kb.runtime/allocation,memory/allocation_copyandmemory/peak_rssnow do real allocate/copy/RSS work, with CPython twins.Evidence
Baseline before this change: generated C had no allocation counters; the memory suite subjects were
return 0/pass; harness JSON only had stdoutallocations:/copies:(always 0) plus/usr/bin/timeRSS on the memory suite.Targeted proof that exercises the changed behaviour:
flowc: PASS(type_id_ok=1,rt_summary_ok=1, profiler prelude and__flowc_str_concatnviaflow_mem_malloc)./flow tool tests/cgen/run.flow mem_profile string_concat string_concat_chain attributes_not_spliced grow_helpers_memory lifetime_domains_no_trace— PASS./flow tool tests/scripts/mem_profile.flow— 4/4./flow tool tests/bench_harness/run.flow— pass=46 fail=0./flow tool tests/cli/run.flow compile_hello compile_isolated_root python_source— PASS (checksums unchanged vs perf: first-slice string concat and buffered text I/O (#747) #1337+profiler)./flow tool python_ratchet— PASS (new twins are under exemptbenchmarks/baselines/python/)Why that proof would detect the old failure or regression: old flowc omits
flow_mem_profile_init; a silent-when-unset failure would print a report with the variable empty; a missing malloc rewrite would fail the golden and theallocations: 1/heap_bytes: 64e2e check; peak-live that ignoredfreewould report 64000 instead of 64 on the allocation row; a rawmallocin__flowc_str_concatnwould miss n-way concat allocations.Repository gate(s) run:
env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)"→flowc: PASS(after rebase onto feat: cross-module @rt_safe/@lifetime summaries (#765) #1342)./compiler/scripts/bootstrap_from_c.sh --regen→ fixed point at gen3./compiler/scripts/bootstrap_from_c.sh --verify→ALL PASS bootstrap_from_cGenerated/bootstrap state:
compiler/bootstrap/flowc_stage_a.cregenerated after rebasing onto main's #1342@rt_safe/@lifetimesquash (ee7432b2).CI on
24c7bd8efailedflowc self-hostbecauseparity_mlirstill had the stub-program digest for the three filled harness rows.compiler/fixtures/mlir/corpus.txtnow records the flowc MLIR digests for those three files only.Remaining gaps (not this PR)
memcpyin some helpers is not all routed (string concat copy volume is counted explicitly).Risk
Compatibility, performance, security, lifetime, backend, or release implications:
Dormant unless
FLOW_MEM_PROFILEis set. One extra branch per routed allocation on the default path. No language syntax change.docs/project/Questions.mdupdated if this needs a language-design decision.Compatibility
docs/project/CHANGELOG.md.Agent handoff
Rebased onto
origin/main(ee7432b2, #1342).FLOW_MEM_PROFILEand golden retargets kept.__flowc_str_concatnusesflow_mem_malloc. Bootstrap regenerated. Head isd154801e48935bd2b0c238ca62bf0c6a7cdd6d65. Do not merge.